From 37b03a11b118fa9c19b34de5db6a3c2b468ec37f Mon Sep 17 00:00:00 2001 From: Asias He Date: Fri, 5 Apr 2013 10:51:51 +0800 Subject: [PATCH] Imported Upstream version 0.4.0 --- .npmignore | 18 ++ AUTHORS | 5 +- CMakeLists.txt | 11 +- INSTALL | 13 -- NEWS | 14 ++ README | 16 ++ binding.gyp | 27 +++ data/CMakeLists.txt | 8 +- data/cn/cn-it.txt | 282 +++++++++++++++++++++- data/cn/cn-name.txt | 6 +- data/cn/to_cn_phrases.txt | 284 +++++++++++++++++++++- data/jp/to_jp_variants.txt | 388 ++++++++++++++++++++++++++++++ data/scheme/st_multi.txt | 35 ++- data/scheme/st_multi_rare.txt | 28 --- data/scheme/variant.txt | 3 +- data/scripts/common.py | 5 +- data/simp_to_trad/characters.txt | 2 +- data/simp_to_trad/phrases.txt | 20 +- data/trad_to_simp/characters.txt | 2 + data/tw/from_tw_variants.txt | 3 +- data/tw/to_tw_phrases.txt | 272 ++++++++++++++++++++- data/tw/to_tw_variants.txt | 2 + data/tw/tw-it.txt | 389 +++++++++++++++++++++++++------ data/tw/tw-name.txt | 158 +++++++------ gypi/configs.gypi | 25 ++ gypi/dicts.gypi | 60 +++++ gypi/global.gypi | 11 + gypi/opencc_dict.gypi | 17 ++ node/binding.cc | 163 +++++++++++++ node/demo.js | 11 + node/opencc.js | 36 +++ node/test.js | 64 +++++ opencc.gyp | 39 ++++ package.json | 28 +++ release.sh | 3 +- src/common.h | 54 +++++ src/config_reader.c | 45 ++-- src/config_reader.h | 7 +- src/converter.c | 3 +- src/converter.h | 4 +- src/dictionary/datrie.c | 10 +- src/dictionary/text.c | 5 +- src/dictionary_group.c | 75 ++++-- src/dictionary_group.h | 8 +- src/dictionary_set.c | 15 +- src/dictionary_set.h | 9 +- src/encoding.c | 2 +- src/encoding.h | 2 +- src/opencc.c | 17 +- src/opencc.h | 6 +- src/opencc_types.h | 9 +- src/tools/CMakeLists.txt | 4 + src/tools/opencc.c | 87 ++++--- src/tools/opencc_dict.c | 14 +- src/utils.c | 129 ++++++++++ src/utils.h | 37 +-- 56 files changed, 2595 insertions(+), 395 deletions(-) create mode 100644 .npmignore delete mode 100644 INSTALL create mode 100644 binding.gyp create mode 100644 data/jp/to_jp_variants.txt delete mode 100644 data/scheme/st_multi_rare.txt create mode 100644 gypi/configs.gypi create mode 100644 gypi/dicts.gypi create mode 100644 gypi/global.gypi create mode 100644 gypi/opencc_dict.gypi create mode 100644 node/binding.cc create mode 100644 node/demo.js create mode 100644 node/opencc.js create mode 100644 node/test.js create mode 100644 opencc.gyp create mode 100644 package.json create mode 100644 src/common.h diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..b18f6ea --- /dev/null +++ b/.npmignore @@ -0,0 +1,18 @@ +.npmignore +.gitignore +CMakeLists.txt +*.cmake +merge.sh + +/po +/doc +/data/scripts +/data/scheme +/src/wrapper +/build +/other +/debug.sh +/release.sh +/opencc.pc.in +/opencc.gyp +/INSTALL diff --git a/AUTHORS b/AUTHORS index 5937a15..156feef 100644 --- a/AUTHORS +++ b/AUTHORS @@ -6,4 +6,7 @@ Peng Huang Kefu Chai LI Daobing Asias -Peng Wu \ No newline at end of file +Peng Wu +Xiaojun Ma +佛振 + diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c4cb6d..ef15058 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,13 +20,14 @@ cmake_minimum_required(VERSION 2.8) set (PACKAGE_NAME opencc) project (${PACKAGE_NAME} C) +include (CTest) enable_testing() ######## Package information set (PACKAGE_URL http://code.google.com/p/opencc) set (PACKAGE_BUGREPORT http://code.google.com/p/opencc/issues/entry) set (OPENCC_VERSION_MAJOR 0) -set (OPENCC_VERSION_MINOR 3) +set (OPENCC_VERSION_MINOR 4) set (OPENCC_VERSION_REVISION 0) if (CMAKE_BUILD_TYPE MATCHES Debug) @@ -38,6 +39,14 @@ set ( ${OPENCC_VERSION_MAJOR}.${OPENCC_VERSION_MINOR}.${OPENCC_VERSION_REVISION}${version_suffix} ) +set(CPACK_SOURCE_PACKAGE_FILE_NAME + "${PACKAGE_NAME}-${OPENCC_VERSION_MAJOR}.${OPENCC_VERSION_MINOR}.${OPENCC_VERSION_REVISION}" +) +set(CPACK_SOURCE_IGNORE_FILES + "/build/;/release/;/debug/;/.git/;.gitignore;~$;${CPACK_SOURCE_IGNORE_FILES}" +) +include(CPack) + ######## Validation if (ENABLE_GETTEXT) diff --git a/INSTALL b/INSTALL deleted file mode 100644 index 1ce22f0..0000000 --- a/INSTALL +++ /dev/null @@ -1,13 +0,0 @@ -1. Make a directory and check in. - - mkdir build - cd build - -2. Build sources. - - cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release -D ENABLE_GETTEXT:BOOL=ON .. - make - -3. Install. - - sudo make install \ No newline at end of file diff --git a/NEWS b/NEWS index 4293c93..9e65265 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,17 @@ +== Ver 0.4.0 == + +2013年3月2日 + + * 修正「雕」「谥」「峯」轉換,新增數百條臺灣科技詞彙。 + * 修正命令行-h錯誤。 + * 修正長行讀取錯誤。 + * 修正錯誤類型拼寫錯誤。 + * 修正UTF-8編碼轉換錯誤。 + * 自動跳過UTF-8的BOM。 + * 修正配置和數據文件相對路徑問題。 + * 增加了gyp編譯系統。 + * 增加了Node.js接口。 + == Ver 0.3.0 == 2011年12月2日 diff --git a/README b/README index 921a861..7fb4b7e 100644 --- a/README +++ b/README @@ -6,3 +6,19 @@ An opensource project for conversion between Traditional Chinese and Simplified 中文簡繁轉換開源項目,支持詞彙級别的轉換、異體字轉換和地區習慣用詞轉換(中國大陸、臺灣、香港)。 http://code.google.com/p/opencc/ + +Build steps with CMake + +1. Make a directory and check in. + + mkdir build + cd build + +2. Build sources. + + cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release -D ENABLE_GETTEXT:BOOL=ON .. + make + +3. Install. + + sudo make install diff --git a/binding.gyp b/binding.gyp new file mode 100644 index 0000000..094493d --- /dev/null +++ b/binding.gyp @@ -0,0 +1,27 @@ +{ + "includes": [ + "gypi/global.gypi", + "gypi/configs.gypi", + "gypi/dicts.gypi", + ], + "targets": [{ + "target_name": "binding", + "sources": [ + "node/binding.cc", + "src/config_reader.c", + "src/converter.c", + "src/dictionary_group.c", + "src/dictionary_set.c", + "src/encoding.c", + "src/utils.c", + "src/opencc.c", + "src/dictionary/abstract.c", + "src/dictionary/datrie.c", + "src/dictionary/text.c" + ], + "dependencies": [ + "configs", + "dicts", + ] + }] +} diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt index 5eaadf8..31c4e56 100644 --- a/data/CMakeLists.txt +++ b/data/CMakeLists.txt @@ -92,4 +92,10 @@ install( ${CHINA_DICT_FILES} DESTINATION ${DIR_SHARE_OPENCC} -) \ No newline at end of file +) + +if (BUILD_TESTING) + foreach (DICT ${TAIWAN_DICT_FILES} ${CHINA_DICT_FILES}) + configure_file(${DICT} ${PROJECT_BINARY_DIR}/data COPYONLY) + endforeach (DICT) +endif (BUILD_TESTING) diff --git a/data/cn/cn-it.txt b/data/cn/cn-it.txt index d82fc8f..3297b23 100644 --- a/data/cn/cn-it.txt +++ b/data/cn/cn-it.txt @@ -1,68 +1,338 @@ +PN接面 PN結 +SQL隱碼攻擊 SQL注入 SQL注入攻擊 三極體 三極管 -串列 串行 +下拉選單 下拉列表 +中介軟體 中間件 +串列埠 串口 串行端口 +主機板 主板 +主開機記錄 主引導記錄 乙太網 以太網 二極體 二極管 +互動 交互 互動式 交互式 人工智慧 人工智能 -介面 接口 +介面 接口 界面 +介面卡 適配器 +代碼 代碼 伺服器 服務器 +佇列 隊列 +位元 比特 +位元率 比特率 位元組 字節 +位元速率 碼率 +位址 地址 +位址列 地址欄 +低級 低級 +低階 低級 +作業系統 操作系統 +使用者 用戶 +來電轉駁 呼叫轉移 +例項 實例 +信號 信號 +偵錯 調試 +偵錯程式 調試器 +傷心小棧 紅心大戰 +價效比 性價比 優先順序 優先級 儲存 保存 +元件 組件 光碟 光盤 光碟機 光驅 +入口網站 門戶網站 +內建 內置 +內碼表 代碼頁 全形 全角 +全球資訊網 萬維網 +函數語言程式設計 函數式編程 +刀鋒伺服器 刀片服務器 +分散式 分佈式 +分時多工 時分複用 +分時多重進接 時分多址 +分碼多重進接 碼分多址 +分空間多重進接 空分多址 +分頻多工 頻分複用 +分頻多重進接 頻分多址 列印 打印 +列舉 枚舉 +剪下 剪切 +剪貼簿 剪貼板 +副檔名 擴展名 文件擴展名 +匯入 導入 +匯出 導出 匯流排 總線 區域網 局域網 半形 半角 印表機 打印机 +原始檔 源文件 +原始碼 源代碼 +原生代碼 本地代碼 +參數列 參數表 +取樣 採樣 +取樣率 采样率 +名稱空間 命名空間 +向量 矢量 +呼叫 調用 +命令列 命令行 +啟用 激活 +單核心 宏內核 +回撥 回調 +圖示 圖標 +地址 地址 埠 端口 +執行緒 線程 +執行長 首席執行官 +壁紙 壁紙 +外來鍵 外鍵 +外接 外置 +多型 多態 +多執行緒 多線程 +多工 多任務 太空梭 航天飛機 字元 字符 +字型 字體 字型檔 字庫 +字尾 後綴 字符集 字符集 +字首 前綴 +存取 訪問 存檔 存盤 +宕機 死機 定址 尋址 +實例 實例 +實體地址 物理地址 +實體記憶體 物理内存 寬頻 寬帶 +對映 映射 +對話方塊 對話框 +對象 對象 +巢狀 嵌套 +工作列 任務欄 +工作管理員 任務管理器 +平行計算 並行計算 +序列 串行 +序號產生器 註冊機 +建構函式 構造函數 +彙編 彙編 +影印 複印 +影象 圖像 +後設資料 元數據 +循環 循環 +微控制器 單片機 +快取 緩存 +快取記憶體 高速緩存 快閃記憶體 閃存 感測 傳感 -掃瞄器 掃描儀 +打開 打開 +技術長 首席技術官 +指令式程式設計 命令式編程 +指令碼 腳本 +掃描器 掃描儀 +排程 調度 +控制代碼 句柄 控制項 控件 +摺積 捲積 +擷取 截取 攜帶型 便攜式 +支持者 支持者 +支援 支持 +效能 性能 +整合 集成 +數位 數字 +數位印刷 數字印刷 +數位電子 數字電子 +數位電路 數字電路 +數字 數字 數據機 調製解調器 +文件 文檔 +文字 文本 +文書處理 文字處理 +映象 鏡像 +映象管 顯像管 +時脈頻率 時鐘頻率 晶片 芯片 -模擬 仿真 +智慧 智能 +智慧財產權 知識產權 +有失真壓縮 有損壓縮 +核心 內核 +桌上型 桌面型 +桌上型電腦 臺式機 +桌布 壁紙 +標頭檔案 頭文件 +模擬 仿真 模擬 +模組 模塊 +檔名 文件名 +檔案 文件 +檢視 查看 視圖 欄位 字段 +正規化 範式 +正規表示式 正則表達式 +氣泡跑需 冒泡排序 +永續性 持久性 +波長分波多工 波分複用 +消息 消息 游標 光標 +溢位 溢出 滑鼠 鼠標 演算法 算法 +無失真壓縮 無損壓縮 +燒錄 刻錄 +營運長 首席運營官 +物件 對象 +物件導向 面向對象 +狀態列 狀態欄 +畫素 像素 +登入 登錄 +登出 註銷 +目的碼 目標代碼 +直譯器 解釋器 +相容 兼容 +相簿 相冊 +真實模式 實模式 硬碟 硬盤 硬體 硬件 碟片 盤片 +碟符 盤符 磁碟 磁盤 磁軌 磁道 +社區 社區 +社羣 社區 +程序 進程 +程序導向 面向過程 +程序式程式設計 過程式編程 +程式 程序 +程式碼 代碼 +程式設計 編程 +程式設計師 程序員 +程式語言 編程語言 +稽覈 審覈 +積體電路 集成電路 +空間多工 空分複用 +簡報 演示文稿 簡訊 短信 -網路 網路 +粘貼 粘貼 +終端使用者 最終用戶 +組合語言 彙編語言 +組譯 彙編 +網咖 網吧 +網路 網絡 +網路上的芳鄰 網上鄰居 網際網路 互聯網 +線上 在線 +縮圖 縮略圖 +縮排 縮進 +繫結 綁定 +膝上型電腦 筆記本電腦 +菜單 菜單 +藍芽 藍牙 +虛擬函式 虛函數 +虛擬機器 虛擬機 +虛擬碼 僞代碼 +螢幕 屏幕 +行內函數 內聯函數 +行動式 便攜式 +行動硬碟 移動硬盤 +行動通訊 移動通信 行動電話 移動電話 +表示式 表達式 +裝置 設備 +覈取按鈕 複選按鈕 +覈取方塊 複選框 +視窗 窗口 +視覺化 可視化 +視訊 視頻 +視訊記憶體 顯存 解析度 分辨率 +解構函式 析構函數 +解除安裝 卸載 +觸控式螢幕 觸摸屏 +訊息 消息 +訊號 信號 +訊雜比 信噪比 +訪問 訪問 +設定 設置 許可權 權限 +調色盤 調色板 +調變 調制 變數 變量 +貼上 粘貼 資料 數據 +資料來源 數據源 +資料倉儲 數據倉庫 +資料包 數據報 +資料夾 文件夾 資料庫 數據庫 +資料探勘 數據挖掘 資訊 信息 +資訊保安 信息安全 資訊理論 信息論 +資訊科技 信息技術 +資訊長 首席信息官 +超程式設計 元編程 軟碟機 軟驅 軟體 軟件 載入 加載 +載入程式 引導程序 +迴圈 循環 +通訊 通信 +通道 信道 +連結 鏈接 +連結串列 鏈表 +連線 連接 進位制 進制 +進程 進程 +進階 高端 高級 運算元 算子 +過載 重載 +遞迴 遞歸 +遠端 遠程 +遮蔽 屏蔽 +選單 菜單 +邏輯閘 邏輯門 +部落格 博客 +都會網路 城域王 +釋出 發佈 +重新命名 重命名 +重新整理 刷新 +重灌 重裝 +金氧半導體 金屬氧化物半導體 +金鑰 密鑰 +錄影 錄像 +鐳射 激光 +開啟 打開 +閘流體 晶閘管 +閘道器 網關 +閘電路 門電路 +關聯式資料庫 關係數據庫 防寫 寫保護 +防毒 殺毒 +陣列 數組 +雜湊 哈希 散列 離線 脫機 +雲端儲存 雲存儲 +雲端計算 雲計算 +電腦保安 計算機安全 +電腦科學 計算機科學 非同步 異步 +面板 皮膚 音效卡 聲卡 +音訊 音頻 +頁尾 頁腳 +頁首 頁眉 預設 缺省 預設值 默認值 +頻寬 帶寬 +類别範本 類模板 +類比 模擬 +類比電子 模擬電子 +類比電路 模擬電路 顯示卡 顯卡 -點陣圖 位圖 \ No newline at end of file +高級 高級 +高階 高端 高級 +高階函數 高階函數 +點選 點擊 +點陣圖 位圖 +隨機亂數 随机数 +型別 類型 +型別註釋 類型簽名 +純粹函數式程式語言 純函數式編程語言 +運算子 運算符 diff --git a/data/cn/cn-name.txt b/data/cn/cn-name.txt index 4cb4106..60aa9a3 100644 --- a/data/cn/cn-name.txt +++ b/data/cn/cn-name.txt @@ -1,4 +1,5 @@ 亞塞拜然 阿塞拜疆 +傅立葉 傅里葉 克羅埃西亞 克羅地亞 列支敦斯登 列支敦士登 加彭 加蓬 @@ -18,18 +19,21 @@ 塔吉克 塔吉克斯坦 塞席爾 塞舌爾 塞普勒斯 塞浦路斯 +夏農 香農 多明尼加 多米尼加 奈及利亞 尼日利亞 安地卡及巴布達 安提瓜和巴布達 宏都拉斯 洪都拉斯 寮國 老撾 尚比亞 贊比亞 +尤拉 歐拉 尼日 尼日爾 巴布亞紐幾內亞 巴布亞新幾内亚 巴貝多 巴巴多斯 布吉納法索 布基納法索 帛琉 帕劳 幾內亞比索 幾內亞比紹 +快捷半導體 仙童半導體 斯洛維尼亞 斯洛文尼亞 查德 乍得 格瑞那達 格林納達 @@ -74,4 +78,4 @@ 那杜 溫納圖萬 阿拉伯聯合大公國 阿拉伯聯合酋長國 馬利共和國 馬里共和國 -馬爾地夫 馬爾代夫 \ No newline at end of file +馬爾地夫 馬爾代夫 diff --git a/data/cn/to_cn_phrases.txt b/data/cn/to_cn_phrases.txt index 2f28037..8a41d38 100644 --- a/data/cn/to_cn_phrases.txt +++ b/data/cn/to_cn_phrases.txt @@ -1,24 +1,71 @@ +PN接面 PN結 +SQL隱碼攻擊 SQL注入 SQL注入攻擊 三極體 三極管 -串列 串行 +下拉選單 下拉列表 +中介軟體 中間件 +串列埠 串口 串行端口 +主機板 主板 +主開機記錄 主引導記錄 乙太網 以太網 乳酪 奶酪 二極體 二極管 +互動 交互 互動式 交互式 亞塞拜然 阿塞拜疆 人工智慧 人工智能 -介面 接口 +介面 接口 界面 +介面卡 適配器 +代碼 代碼 伺服器 服務器 +佇列 隊列 +位元 比特 +位元率 比特率 位元組 字節 +位元速率 碼率 +位址 地址 +位址列 地址欄 +低級 低級 +低階 低級 +作業系統 操作系統 +使用者 用戶 +來電轉駁 呼叫轉移 +例項 實例 +信號 信號 +偵錯 調試 +偵錯程式 調試器 +傅立葉 傅里葉 +傷心小棧 紅心大戰 +價效比 性價比 優先順序 優先級 儲存 保存 +元件 組件 光碟 光盤 光碟機 光驅 克羅埃西亞 克羅地亞 +入口網站 門戶網站 +內建 內置 +內碼表 代碼頁 全形 全角 +全球資訊網 萬維網 冷盤 凉菜 +函數語言程式設計 函數式編程 +刀鋒伺服器 刀片服務器 +分散式 分佈式 +分時多工 時分複用 +分時多重進接 時分多址 +分碼多重進接 碼分多址 +分空間多重進接 空分多址 +分頻多工 頻分複用 +分頻多重進接 頻分多址 列印 打印 列支敦斯登 列支敦士登 +列舉 枚舉 +剪下 剪切 +剪貼簿 剪貼板 +副檔名 擴展名 文件擴展名 加彭 加蓬 +匯入 導入 +匯出 導出 匯流排 總線 區域網 局域網 千里達及托巴哥 特立尼達和多巴哥 @@ -27,129 +74,356 @@ 印表機 打印机 厄利垂亞 厄立特里亞 厄瓜多 厄瓜多爾 +原始檔 源文件 +原始碼 源代碼 +原生代碼 本地代碼 +參數列 參數表 +取樣 採樣 +取樣率 采样率 史瓦濟蘭 斯威士蘭 吉布地 吉布堤 吉里巴斯 基里巴斯 +名稱空間 命名空間 吐瓦魯 圖瓦盧 +向量 矢量 +呼叫 調用 +命令列 命令行 哈薩克 哈萨克斯坦 哥斯大黎加 哥斯達黎加 +啟用 激活 喬治亞 格魯吉亞 +單核心 宏內核 +回撥 回調 +圖示 圖標 土庫曼 土庫曼斯坦 +地址 地址 坦尚尼亞 坦桑尼亞 +型別 類型 +型別註釋 類型簽名 埠 端口 +執行緒 線程 +執行長 首席執行官 塔吉克 塔吉克斯坦 塞席爾 塞舌爾 塞普勒斯 塞浦路斯 +壁紙 壁紙 +夏農 香農 +外來鍵 外鍵 +外接 外置 +多型 多態 +多執行緒 多線程 +多工 多任務 多明尼加 多米尼加 太空梭 航天飛機 奈及利亞 尼日利亞 子音 輔音 字元 字符 +字型 字體 字型檔 字庫 +字尾 後綴 字符集 字符集 +字首 前綴 +存取 訪問 存檔 存盤 安地卡及巴布達 安提瓜和巴布達 宏都拉斯 洪都拉斯 +宕機 死機 定址 尋址 +實例 實例 +實體地址 物理地址 +實體記憶體 物理内存 寬頻 寬帶 寮國 老撾 +對映 映射 +對話方塊 對話框 +對象 對象 尚比亞 贊比亞 +尤拉 歐拉 尼日 尼日爾 +巢狀 嵌套 +工作列 任務欄 +工作管理員 任務管理器 巴布亞紐幾內亞 巴布亞新幾内亚 巴貝多 巴巴多斯 布吉納法索 布基納法索 帛琉 帕劳 +平行計算 並行計算 幾內亞比索 幾內亞比紹 +序列 串行 +序號產生器 註冊機 +建構函式 構造函數 +彙編 彙編 +影印 複印 +影象 圖像 +後設資料 元數據 +循環 循環 +微控制器 單片機 +快取 緩存 +快取記憶體 高速緩存 +快捷半導體 仙童半導體 快閃記憶體 閃存 感測 傳感 -掃瞄器 掃描儀 +打開 打開 +技術長 首席技術官 +指令式程式設計 命令式編程 +指令碼 腳本 +掃描器 掃描儀 +排程 調度 +控制代碼 句柄 控制項 控件 +摺積 捲積 +擷取 截取 攜帶型 便攜式 +支持者 支持者 +支援 支持 +效能 性能 +整合 集成 +數位 數字 +數位印刷 數字印刷 +數位電子 數字電子 +數位電路 數字電路 +數字 數字 數據機 調製解調器 +文件 文檔 +文字 文本 +文書處理 文字處理 斯洛維尼亞 斯洛文尼亞 +映象 鏡像 +映象管 顯像管 +時脈頻率 時鐘頻率 晶片 芯片 +智慧 智能 +智慧財產權 知識產權 +有失真壓縮 有損壓縮 查德 乍得 +核心 內核 格瑞那達 格林納達 -模擬 仿真 +桌上型 桌面型 +桌上型電腦 臺式機 +桌布 壁紙 +標頭檔案 頭文件 +模擬 仿真 模擬 +模組 模塊 模里西斯 毛里求斯 +檔名 文件名 +檔案 文件 +檢視 查看 視圖 欄位 字段 +正規化 範式 +正規表示式 正則表達式 母音 元音 +氣泡跑需 冒泡排序 +永續性 持久性 汶萊 文莱 沙烏地阿拉伯 沙特阿拉伯 波士尼亞赫塞哥維納 波斯尼亞黑塞哥維那 波札那 博茨瓦納 +波長分波多工 波分複用 +消息 消息 游標 光標 +溢位 溢出 滑鼠 鼠標 演算法 算法 烏茲別克 烏茲別克斯坦 +無失真壓縮 無損壓縮 +燒錄 刻錄 +營運長 首席運營官 片語 詞組 +物件 對象 +物件導向 面向對象 +狀態列 狀態欄 獅子山 塞拉利昂 瓜地馬拉 危地馬拉 甘比亞 岡比亞 +畫素 像素 +登入 登錄 +登出 註銷 盧安達 盧旺達 +目的碼 目標代碼 +直譯器 解釋器 +相容 兼容 +相簿 相冊 +真實模式 實模式 矽 硅 硬碟 硬盤 硬體 硬件 碟片 盤片 +碟符 盤符 磁碟 磁盤 磁軌 磁道 +社區 社區 +社羣 社區 +程序 進程 +程序導向 面向過程 +程序式程式設計 過程式編程 +程式 程序 +程式碼 代碼 +程式設計 編程 +程式設計師 程序員 +程式語言 編程語言 +稽覈 審覈 +積體電路 集成電路 +空間多工 空分複用 突尼西亞 突尼斯 笨豬跳 蹦极 +簡報 演示文稿 簡訊 短信 +粘貼 粘貼 紐西蘭 新西蘭 +純粹函數式程式語言 純函數式編程語言 索羅門羣島 所羅門羣島 索馬利亞 索馬里 +終端使用者 最終用戶 +組合語言 彙編語言 +組譯 彙編 維德角 佛得角 -網路 網路 +網咖 網吧 +網路 網絡 +網路上的芳鄰 網上鄰居 網際網路 互聯網 +線上 在線 +縮圖 縮略圖 +縮排 縮進 +繫結 綁定 義大利 意大利 聖克里斯多福及尼維斯 聖基茨和尼維斯 聖文森及格瑞那丁 聖文森特和格林納丁斯 聖露西亞 聖盧西亞 聖馬利諾 聖馬力諾 肯亞 肯尼亞 +膝上型電腦 筆記本電腦 茅利塔尼亞 毛里塔尼亞 莫三比克 莫桑比克 +菜單 菜單 萬那杜 瓦努阿圖 葉門 也門 葛摩 科摩羅 蒲隆地 布隆迪 蓋亞那 圭亞那 +藍芽 藍牙 蘇利南 蘇裏南 +虛擬函式 虛函數 +虛擬機器 虛擬機 +虛擬碼 僞代碼 +螢幕 屏幕 +行內函數 內聯函數 +行動式 便攜式 +行動硬碟 移動硬盤 +行動通訊 移動通信 行動電話 移動電話 衣索比亞 埃塞俄比亞 +表示式 表達式 +裝置 設備 +覈取按鈕 複選按鈕 +覈取方塊 複選框 +視窗 窗口 +視覺化 可視化 +視訊 視頻 +視訊記憶體 顯存 解析度 分辨率 +解構函式 析構函數 +解除安裝 卸載 +觸控式螢幕 觸摸屏 計程車 出租车 +訊息 消息 +訊號 信號 +訊雜比 信噪比 +訪問 訪問 +設定 設置 許可權 權限 +調色盤 調色板 +調變 調制 諾魯 瑙魯 變數 變量 象牙海岸 科特迪瓦 貝南 貝寧 貝里斯 伯利茲 +貼上 粘貼 資料 數據 +資料來源 數據源 +資料倉儲 數據倉庫 +資料包 數據報 +資料夾 文件夾 資料庫 數據庫 +資料探勘 數據挖掘 資訊 信息 +資訊保安 信息安全 資訊理論 信息論 +資訊科技 信息技術 +資訊長 首席信息官 賓士 奔馳 賴比瑞亞 利比里亞 賴索托 萊索托 +超程式設計 元編程 軟碟機 軟驅 軟體 軟件 載入 加載 +載入程式 引導程序 辛巴威 津巴布韋 迦納 加納 +迴圈 循環 +通訊 通信 +通道 信道 速食麵 方便麵 +連結 鏈接 +連結串列 鏈表 +連線 連接 進位制 進制 +進程 進程 +進階 高端 高級 運算元 算子 +運算子 運算符 +過載 重載 +遞迴 遞歸 +遠端 遠程 +遮蔽 屏蔽 +選單 菜單 +邏輯閘 邏輯門 那杜 溫納圖萬 +部落格 博客 +都會網路 城域王 +釋出 發佈 +重新命名 重命名 +重新整理 刷新 +重灌 重裝 +金氧半導體 金屬氧化物半導體 +金鑰 密鑰 +錄影 錄像 +鐳射 激光 +開啟 打開 +閘流體 晶閘管 +閘道器 網關 +閘電路 門電路 +關聯式資料庫 關係數據庫 防寫 寫保護 +防毒 殺毒 阿拉伯聯合大公國 阿拉伯聯合酋長國 +陣列 數組 +隨機亂數 随机数 +雜湊 哈希 散列 離線 脫機 +雲端儲存 雲存儲 +雲端計算 雲計算 +電腦保安 計算機安全 +電腦科學 計算機科學 非同步 異步 +面板 皮膚 音效卡 聲卡 +音訊 音頻 +頁尾 頁腳 +頁首 頁眉 預設 缺省 預設值 默認值 +頻寬 帶寬 +類别範本 類模板 +類比 模擬 +類比電子 模擬電子 +類比電路 模擬電路 顯示卡 顯卡 馬利共和國 馬里共和國 馬爾地夫 馬爾代夫 +高級 高級 +高階 高端 高級 +高階函數 高階函數 +點選 點擊 點陣圖 位圖 diff --git a/data/jp/to_jp_variants.txt b/data/jp/to_jp_variants.txt new file mode 100644 index 0000000..5cf4257 --- /dev/null +++ b/data/jp/to_jp_variants.txt @@ -0,0 +1,388 @@ +乘 乗 +亂 乱 +亙 亘 +亞 亜 +佛 仏 +來 来 +倂 併 +假 仮 +傳 伝 +僞 偽 +價 価 +儉 倹 +兒 児 +兩 両 +剩 剰 +劍 剣 +劑 剤 +勞 労 +勳 勲 +勵 励 +勸 勧 +區 区 +卷 巻 +卽 即 +參 参 +啞 唖 +單 単 +嚙 噛 +嚴 厳 +囑 嘱 +圈 圏 +國 国 +圍 囲 +圓 円 +圖 図 +團 団 +增 増 +墮 堕 +壓 圧 +壘 塁 +壞 壊 +壤 壌 +壯 壮 +壹 壱 +壽 寿 +奧 奥 +奬 奨 +孃 嬢 +學 学 +寢 寝 +實 実 +寫 写 +寬 寛 +寶 宝 +將 将 +專 専 +對 対 +屆 届 +屛 屏 +屬 属 +峽 峡 +嶽 岳 +巖 巌 +巢 巣 +帶 帯 +幷 并 +廢 廃 +廣 広 +廳 庁 +彈 弾 +彌 弥 +彎 弯 +徑 径 +從 従 +徵 徴 +德 徳 +恆 恒 +惠 恵 +惡 悪 +惱 悩 +愼 慎 +慘 惨 +應 応 +懷 懐 +戀 恋 +戰 戦 +戲 戯 +戾 戻 +拂 払 +拔 抜 +拜 拝 +挾 挟 +插 挿 +揭 掲 +搔 掻 +搖 揺 +搜 捜 +擇 択 +擊 撃 +擔 担 +據 拠 +擧 挙 +擴 拡 +攝 摂 +攪 撹 +收 収 +效 効 +敍 叙 +敕 勅 +數 数 +斷 断 +晚 晩 +晝 昼 +曆 暦 +曉 暁 +曾 曽 +會 会 +枡 桝 +條 条 +棧 桟 +榮 栄 +槪 概 +樂 楽 +樓 楼 +樞 枢 +樣 様 +橫 横 +檢 検 +櫻 桜 +權 権 +歐 欧 +歡 歓 +步 歩 +歷 歴 +歸 帰 +殘 残 +殼 殻 +毆 殴 +每 毎 +氣 気 +涉 渉 +淚 涙 +淨 浄 +淺 浅 +渴 渇 +溪 渓 +溫 温 +滯 滞 +滿 満 +潛 潜 +澁 渋 +澤 沢 +濕 湿 +濟 済 +濱 浜 +濾 沪 +瀧 滝 +瀨 瀬 +灣 湾 +燈 灯 +燒 焼 +營 営 +爐 炉 +爭 争 +爲 為 +犧 犠 +狀 状 +狹 狭 +獨 独 +獵 猟 +獸 獣 +獻 献 +瓣 弁 +甁 瓶 +畫 画 +當 当 +疊 畳 +瘦 痩 +癡 痴 +發 発 +盜 盗 +盡 尽 +眞 真 +硏 研 +碎 砕 +祕 秘 +祿 禄 +禪 禅 +禮 礼 +禱 祷 +稱 称 +稻 稲 +穎 頴 +穗 穂 +穩 穏 +穰 穣 +竊 窃 +竝 並 +粹 粋 +絲 糸 +經 経 +綠 緑 +緖 緒 +緣 縁 +縣 県 +縱 縦 +總 総 +繡 繍 +繩 縄 +繪 絵 +繼 継 +續 続 +纖 繊 +缺 欠 +罐 缶 +聲 声 +聽 聴 +肅 粛 +腦 脳 +膽 胆 +臟 臓 +臺 台 +與 与 +舊 旧 +莊 荘 +莖 茎 +萬 万 +蔣 蒋 +薰 薫 +藏 蔵 +藝 芸 +藥 薬 +蘆 芦 +處 処 +虛 虚 +號 号 +螢 蛍 +蟲 虫 +蠟 蝋 +蠶 蚕 +蠻 蛮 +衞 衛 +裝 装 +襃 褒 +覺 覚 +覽 覧 +觀 観 +觸 触 +謠 謡 +證 証 +譯 訳 +譽 誉 +讀 読 +變 変 +讓 譲 +豐 豊 +豫 予 +貳 弐 +賣 売 +賴 頼 +贊 賛 +踐 践 +輕 軽 +轉 転 +辨 弁 +辭 辞 +辯 弁 +遞 逓 +遲 遅 +邊 辺 +郞 郎 +鄕 郷 +醉 酔 +醫 医 +醬 醤 +釀 醸 +釋 釈 +錄 録 +錢 銭 +鍊 錬 +鎭 鎮 +鐵 鉄 +鑄 鋳 +鑛 鉱 +關 関 +陷 陥 +隨 随 +險 険 +隱 隠 +雙 双 +雜 雑 +霸 覇 +靈 霊 +靜 静 +顯 顕 +飜 翻 +餘 余 +騷 騒 +驅 駆 +驗 験 +驛 駅 +髓 髄 +體 体 +髮 髪 +鬪 闘 +鷄 鶏 +鷗 鴎 +鹼 鹸 +鹽 塩 +麥 麦 +麴 麹 +麵 麺 +黃 黄 +黑 黒 +默 黙 +點 点 +黨 党 +齊 斉 +齋 斎 +齒 歯 +齡 齢 +龍 竜 +欄 欄 +廊 廊 +朗 朗 +虜 虜 +殺 殺 +類 類 +隆 隆 +塚 塚 +猪 猪 +神 神 +祥 祥 +福 福 +諸 諸 +都 都 +侮 侮 +僧 僧 +免 免 +勉 勉 +勤 勤 +卑 卑 +喝 喝 +嘆 嘆 +器 器 +塀 塀 +墨 墨 +層 層 +悔 悔 +慨 慨 +憎 憎 +懲 懲 +敏 敏 +暑 暑 +梅 梅 +海 海 +渚 渚 +漢 漢 +煮 煮 +琢 琢 +碑 碑 +社 社 +祉 祉 +祈 祈 +祐 祐 +祖 祖 +祝 祝 +禍 禍 +禎 禎 +穀 穀 +突 突 +節 節 +練 練 +繁 繁 +署 署 +者 者 +臭 臭 +著 著 +褐 褐 +視 視 +謁 謁 +謹 謹 +賓 賓 +贈 贈 +逸 逸 +難 難 +響 響 +頻 頻 diff --git a/data/scheme/st_multi.txt b/data/scheme/st_multi.txt index fb5a5dd..4b8a0f4 100644 --- a/data/scheme/st_multi.txt +++ b/data/scheme/st_multi.txt @@ -13,12 +13,12 @@ 当 當 噹 「噹」用於擬聲詞,其餘用「當」。 叮噹 噹啷 當然 當年 應當 志 志 誌 與記錄有關用「誌」,其餘用「志」。 志向 志氣 雜誌 日誌 汇 匯 彙 「彙」爲「相同種類聚集成的東西」,「匯」傾向於「水流匯合」一動作。 辭彙 彙編 彙報 匯合 匯款 -系 係 系 繫 「係」強調「關係」,「系」爲一個整體,「繫」與連接有關。 系統 係數 干係 關係 聯繫 維繫 繫鞋帶 +系 系 係 繫 「係」強調「關係」,「系」爲一個整體,「繫」與連接有關。 系統 係數 干係 關係 聯繫 維繫 繫鞋帶 脏 髒 臟 「臟」讀音zang4,意義爲「身體器官」,「髒」讀音zang1,意義爲「不乾淨」。 內臟 骯髒 荡 蕩 盪 與「洗滌」、「搖動」有掛用「盪」,其餘用「蕩」。 盪漾 盪滌 動盪 掃蕩 放蕩 蕩然無存 蕩氣迴腸 获 獲 穫 「獲」一般用於動詞,「穫」一般用於名詞。 不勞而獲 獲益 收穫 采 採 采 「採」用於動詞,其餘用「采」。 採集 博採眾長 丰采 神采奕奕 -里 里 裏 「裏」與「外」相對,其餘用「里」。 里程 故里 裏外 +里 裏 里 「裏」與「外」相對,其餘用「里」。 里程 故里 裏外 钟 鍾 鐘 「鍾」意義爲聚集,「鐘」爲一種樂器。 鍾情 鍾愛 鐘鼓 掩耳盜鐘 饥 飢 饑 「飢」意義爲「吃不飽」,「饑」意義爲「穀物不熟」。 飢餓 饑荒 饑饉 丰 豐 丰 表示「美好的容貌的姿態」用「丰」,其餘一般爲「豐」。 丰采 丰姿 豐富 五穀豐登 張三丰 @@ -98,14 +98,14 @@ 炼 煉 鍊 專指「熔鍊金屬」時用「鍊」,一般意義用「煉」。 鍊鐵 淬鍊 煉乳 修煉 链 鏈 鍊 「鏈」用作一般的「金屬繩狀物」,「鍊」專指首飾。 鎖鏈 鏈接 項鍊 金手鍊 穗 穗 繐 「繐」用作「結紮成的裝飾物」,其餘用「穗」。 麥穗 帽繐 -雕 雕 鵰 「鵰」爲一種猛禽,與「雕刻」有關時用「雕」。 一箭雙鵰 雕刻 雕蟲小技 +雕 彫 鵰 「鵰」爲一種猛禽,與「彫刻」有關時用「彫」。 一箭雙鵰 彫刻 彫蟲小技 梁 樑 梁 與「橋樑」、「棟樑」有關用「樑」,其餘意義爲「梁」。 樑上君子 鼻樑 大梁城 梁朝 梁山 升 升 昇 「昇」字帶有濃烈喜慶氣氛,其餘用「升」。 上升 一升水 旭日東昇 歌舞昇平 摆 擺 襬 表示「衣服下緣的部分」用「襬」,其餘用「擺」。 搖擺 擺放 裙襬 下襬 岩 巖 岩 「岩」只用於「岩石」相關意義,其餘用「巖」。 沉積岩 岩漿 巖壁 中空成巖 娘 娘 孃 「孃」意義爲「母親」,其餘用「娘」。 老孃 爹孃 孃家 姑娘 娘子 婆娘 舞娘 僵 僵 殭 「殭」意義爲「不腐朽的屍體」,其餘用「僵」。 殭屍 殭蠶 僵硬 僵局 李代桃僵 百足之蟲,死而不僵 -药 藥 葯 「葯」特指「花的雄蕊中貯藏劃分的部份」,其餘用「藥」。 醫藥 良藥 芍藥 藥到病除 花葯 +药 藥 葯 「葯」特指「花的雄蕊中貯藏花粉的部份」,其餘用「藥」。 醫藥 良藥 芍藥 藥到病除 花葯 余 餘 余 「余」爲第一人稱代詞或地名。 剩餘 多餘 余吾鎮 蜡 蠟 蜡 「蜡」只用於「蜡月」。 蠟燭 蜂蠟 石蠟 蜡月 出 出 齣 「齣」只用於「一齣戲」。 出入 出道 一齣戲 @@ -167,3 +167,30 @@ 背 背 揹 「揹」作動詞,表示「負荷」,讀陰平聲。 揹黑鍋 揹負 夫 夫 伕 「伕」指「出苦力的人」。 車伕 轎伕 腳伕 迹 蹟 跡 「蹟」特指「前人留下的事物」。 遺蹟 事蹟 奇蹟 +录 錄 彔 「彔」爲雕刻木材,見於古文。 +极 極 极 「极」見於古文。 +愿 願 愿 「愿」見於古文,意義爲「忠厚」﹑「謹慎」。 +胜 勝 胜 「胜」爲「腥」之本字。 +确 確 确 「确」見於古文。 +叶 葉 叶 「叶」爲「協」古異體。 +虫 蟲 虫 「虫」爲「虺」的古字。 +厂 廠 厂 「厂」爲「庵」的古字。 +修 修 脩 「脩」指「乾肉」或「酬金」,古通「修」。 +价 價 价 「价」古義爲僕人。 +合 合 閤 「閤」見於古文,意義爲「宮殿」、「邊門」。 +适 適 适 「适」爲一古字,意義爲「迅速」。 +弥 彌 瀰 「瀰」爲「水深滿的樣子」,只見於古文。 +厘 釐 厘 「厘」見於古文。 +涂 塗 涂 「涂」見於姓氏和古文。 +个 個 箇 个 「箇」用於「箇中」地名「箇舊」,「个」見於古文。 +于 於 于 「于」見於姓氏和古文。 +党 黨 党 「党」只用於「党項族」或姓氏。 +种 種 种 「种」爲姓氏,其餘用「種」。 +万 萬 万 「万」只用於複姓「万俟」。 +范 範 范 「范」只用於姓氏,其餘用「範」。 +沈 瀋 沈 「瀋」意義爲「汁」,亦是河流名,「沈」作姓氏(讀作shen3時)。 +姜 姜 薑 「姜」爲姓氏,「薑」爲一種植物調味料。 +闲 閒 閑 「閑」「閒」在一般意義上爲異體字,其他意義見於古文或通假。 +证 證 証 証諫、士尉以証君 +佑 佑 祐 福祉用「祐」。嘉祐 僧祐 +谥 諡 謚 「諡」用於「諡號」,「謚」見於古文。 diff --git a/data/scheme/st_multi_rare.txt b/data/scheme/st_multi_rare.txt deleted file mode 100644 index dcd5bf6..0000000 --- a/data/scheme/st_multi_rare.txt +++ /dev/null @@ -1,28 +0,0 @@ -录 錄 彔 “彔”爲雕刻木材,見於古文。 -极 極 极 “极”見於古文。 -愿 願 愿 “愿”見於古文,意義爲“忠厚”﹑“謹慎”。 -胜 勝 胜 “胜”爲“腥”之本字。 -确 確 确 “确”見於古文。 -叶 葉 叶 “叶”爲“協”古異體。 -虫 蟲 虫 “虫”爲“虺”的古字。 -厂 廠 厂 “厂”爲“庵”的古字。 -修 修 脩 “脩”指“乾肉”或“酬金”,古通“修”。 -价 價 价 “价”古義爲僕人。 -合 合 閤 “閤”見於古文,意義爲“宮殿”、“邊門”。 -适 適 适 “适”爲一古字,意義爲“迅速”。 -弥 彌 瀰 “瀰”爲“水深滿的樣子”,只見於古文。 -厘 釐 厘 “厘”見於古文。 -涂 塗 涂 “涂”見於姓氏和古文。 -个 個 箇 个 “箇”用於“箇中”地名“箇舊”,“个”見於古文。 -于 於 于 “于”見於姓氏和古文。 -党 黨 党 “党”只用於“党項族”或姓氏。 -种 種 种 “种”爲姓氏,其餘用“種”。 -万 萬 万 “万”只用於複姓“万俟”。 -范 範 范 “范”只用於姓氏,其餘用“範”。 -沈 瀋 沈 “瀋”意義爲“汁”,亦是河流名,“沈”作姓氏(讀作shen3時)。 -姜 薑 姜 “姜”爲姓氏,“薑”爲一種植物調味料。 -挂 掛 挂 “挂”見於古文。 -闲 閒 閑 “閑”“閒”在一般意義上爲異體字,其他意義見於古文或通假。 -证 證 証 証諫、士尉以証君 -芸 芸 蕓 芸香 蕓薹 -佑 佑 祐 福祉用“祐”。嘉祐 僧祐 \ No newline at end of file diff --git a/data/scheme/variant.txt b/data/scheme/variant.txt index 2de5576..1e0a033 100644 --- a/data/scheme/variant.txt +++ b/data/scheme/variant.txt @@ -143,4 +143,5 @@ 餈 餈 糍 拋 拋 抛 糉 糉 粽 -峯 峰 峯 \ No newline at end of file +峯 峰 峯 +鵰 鵰 雕 \ No newline at end of file diff --git a/data/scripts/common.py b/data/scripts/common.py index 3c7069d..ead0e3d 100644 --- a/data/scripts/common.py +++ b/data/scripts/common.py @@ -7,7 +7,10 @@ def sort_items(input_filename, output_filename): for line in input_file: if len(line) == 0: continue - key, value = line.split("\t") + try: + key, value = line.split("\t") + except ValueError: + print line while value[-1] == "\n" or value[-1] == "\r": value = value[:-1] dic[key] = value diff --git a/data/simp_to_trad/characters.txt b/data/simp_to_trad/characters.txt index 4bcb831..0dd6913 100644 --- a/data/simp_to_trad/characters.txt +++ b/data/simp_to_trad/characters.txt @@ -1737,7 +1737,7 @@ 谢 謝 谣 謠 谤 謗 -谥 謚 +谥 諡 謚 谦 謙 谧 謐 谨 謹 diff --git a/data/simp_to_trad/phrases.txt b/data/simp_to_trad/phrases.txt index 89535ef..e60efac 100644 --- a/data/simp_to_trad/phrases.txt +++ b/data/simp_to_trad/phrases.txt @@ -1,15 +1,5 @@ 㓦划 㓦劃 -㔩叶 㔩葉 -䜣合 訢合 -一万 一萬 一丝不挂 一絲不掛 -一个 一個 -一个个 一個個 -一个人 一個人 -一个准 一個準 -一个样 一個樣 -一中一台 一中一臺 -一举千里 一舉千里 一了心愿 一了心願 一了百了 一了百了 一了百当 一了百當 @@ -21,10 +11,7 @@ 一元复始 一元復始 一克 一克 一党 一黨 -一冲 一衝 -一冲一撞 一衝一撞 一冲性子 一沖性子 -一决胜负 一決勝負 一准 一準 一出剧 一齣劇 一出去 一出去 @@ -44,7 +31,6 @@ 一刻千金 一刻千金 一前一后 一前一後 一力承当 一力承當 -一千 一千 一卷 一卷 一厘一毫 一釐一毫 一厢情愿 一廂情願 @@ -63,8 +49,6 @@ 一叶兰 一葉蘭 一叶扁舟 一葉扁舟 一叶知秋 一葉知秋 -一叶蔽目不见泰山 一葉蔽目不見泰山 -一叶障目不见泰山 一葉障目不見泰山 一号木杆 一號木桿 一吊 一吊 一吊钱 一吊錢 @@ -82,8 +66,6 @@ 一喊出 一喊出 一回 一回 一回事 一回事 -一回生两回熟 一回生兩回熟 -一回生二回熟 一回生二回熟 一团 一團 一团和气 一團和氣 一团团 一團團 @@ -1038,7 +1020,6 @@ 不切合实际 不切合實際 不划算 不划算 不利于 不利於 -不到乌江不尽头 不到烏江不盡頭 不前不后 不前不後 不加修饰 不加修飾 不加区别 不加區別 @@ -16580,6 +16561,7 @@ 备抵折旧 備抵折舊 备注 備註 备注栏 備註欄 +复用 複用 复三 復三 复上 覆上 复业 復業 diff --git a/data/trad_to_simp/characters.txt b/data/trad_to_simp/characters.txt index ddac4f2..f1cf822 100644 --- a/data/trad_to_simp/characters.txt +++ b/data/trad_to_simp/characters.txt @@ -433,6 +433,7 @@ 屬 属 岡 冈 岩 岩 +峯 峰 峴 岘 島 岛 峽 峡 @@ -1896,6 +1897,7 @@ 謗 谤 謙 谦 謚 谥 +諡 谥 講 讲 謝 谢 謠 谣 diff --git a/data/tw/from_tw_variants.txt b/data/tw/from_tw_variants.txt index 051e78e..895d089 100644 --- a/data/tw/from_tw_variants.txt +++ b/data/tw/from_tw_variants.txt @@ -18,4 +18,5 @@ 麴 麯 麵 麪 著 着 -凶 兇 \ No newline at end of file +凶 兇 +峰 峯 diff --git a/data/tw/to_tw_phrases.txt b/data/tw/to_tw_phrases.txt index 3c12f6c..0552e7c 100644 --- a/data/tw/to_tw_phrases.txt +++ b/data/tw/to_tw_phrases.txt @@ -1,58 +1,120 @@ +PN結 PN接面 +SQL注入 SQL隱碼攻擊 +SQL注入攻擊 SQL隱碼攻擊 三極管 三極體 -串行 串列 +下拉列表 下拉選單 +並行計算 平行計算 +中間件 中介軟體 +串口 串列埠 +串行 序列 +串行端口 串列埠 +主引導記錄 主開機記錄 +主板 主機板 乍得 查德 也門 葉門 二極管 二極體 互聯網 網際網路 +交互 互動 交互式 互動式 人工智能 人工智慧 +仙童半導體 快捷半導體 +代碼 程式碼 代碼 +代碼頁 內碼表 以太網 乙太網 +任務欄 工作列 +任務管理器 工作管理員 仿真 模擬 伯利茲 貝里斯 位圖 點陣圖 -佐治亞 喬治亞 +低級 低階 低級 佛得角 維德角 -便攜式 攜帶型 +便攜式 行動式 攜帶型 保存 儲存 +信噪比 訊雜比 信息 資訊 +信息安全 資訊保安 +信息技術 資訊科技 信息論 資訊理論 +信號 訊號 信號 +信道 通道 +傅里葉 傅立葉 傳感 感測 +像素 畫素 +僞代碼 虛擬碼 優先級 優先順序 +元數據 後設資料 +元編程 超程式設計 元音 母音 光標 游標 光盤 光碟 光驅 光碟機 克羅地亞 克羅埃西亞 +內核 核心 +內置 內建 +內聯函數 行內函數 全角 全形 +兼容 相容 +冒泡排序 氣泡跑需 凉菜 冷盤 出租车 計程車 +函數式編程 函數語言程式設計 +刀片服務器 刀鋒伺服器 +分佈式 分散式 分辨率 解析度 列支敦士登 列支敦斯登 利比里亞 賴比瑞亞 +刷新 重新整理 +刻錄 燒錄 +前綴 字首 +剪切 剪下 +剪貼板 剪貼簿 加納 迦納 加蓬 加彭 加載 載入 半角 半形 +博客 部落格 博茨瓦納 波札那 卡塔爾 卡達 危地馬拉 瓜地馬拉 +卸載 解除安裝 厄瓜多爾 厄瓜多 厄立特里亞 厄利垂亞 +參數表 參數列 +句柄 控制代碼 +可視化 視覺化 吉布堤 吉布地 +呼叫轉移 來電轉駁 +命令式編程 指令式程式設計 +命令行 命令列 +命名空間 名稱空間 +哈希 雜湊 哈萨克斯坦 哈薩克 哥斯達黎加 哥斯大黎加 -因特網 網際網路 +單片機 微控制器 +回調 回撥 +圖像 影象 +圖標 圖示 圖瓦盧 吐瓦魯 土庫曼斯坦 土庫曼 +在線 線上 圭亞那 蓋亞那 +地址 地址 位址 +地址欄 位址列 坦桑尼亞 坦尚尼亞 埃塞俄比亞 衣索比亞 +城域王 都會網路 基里巴斯 吉里巴斯 塔吉克斯坦 塔吉克 塞拉利昂 獅子山 塞浦路斯 塞普勒斯 塞舌爾 塞席爾 +壁紙 桌布 壁紙 +外置 外接 +外鍵 外來鍵 +多任務 多工 +多態 多型 多米尼加 多明尼加 +多線程 多執行緒 奔馳 賓士 奶酪 乳酪 字庫 字型檔 @@ -60,90 +122,231 @@ 字符 字元 字符集 字符集 字節 位元組 +字體 字型 存盤 存檔 安提瓜和巴布達 安地卡及巴布達 +宏內核 單核心 +密鑰 金鑰 +實例 例項 實例 +實模式 真實模式 +審覈 稽覈 寫保護 防寫 寬帶 寬頻 尋址 定址 +對話框 對話方塊 +對象 物件 對象 +導入 匯入 +導出 匯出 尼日利亞 奈及利亞 尼日爾 尼日 局域網 區域網 +屏幕 螢幕 +屏蔽 遮蔽 岡比亞 甘比亞 +嵌套 巢狀 巴巴多斯 巴貝多 巴布亞新幾内亚 巴布亞紐幾內亞 布基納法索 布吉納法索 布隆迪 蒲隆地 帕劳 帛琉 +帶寬 頻寬 幾內亞比紹 幾內亞比索 +引導程序 載入程式 +彙編 彙編 組譯 +彙編語言 組合語言 +後綴 字尾 +循環 迴圈 循環 +性價比 價效比 +性能 效能 意大利 義大利 +截取 擷取 所羅門羣島 索羅門羣島 打印 列印 打印机 印表機 -掃描儀 掃瞄器 +打開 開啟 打開 +持久性 永續性 +捲積 摺積 +掃描儀 掃描器 +採樣 取樣 接口 介面 控件 控制項 +操作系統 作業系統 +擴展名 副檔名 +支持 支援 +支持者 支持者 +散列 雜湊 +數字 數字 數位 +數字印刷 數位印刷 +數字電子 數位電子 +數字電路 數位電路 數據 資料 +數據倉庫 資料倉儲 +數據報 資料包 數據庫 資料庫 +數據挖掘 資料探勘 +數據源 資料來源 +數組 陣列 +文件 檔案 +文件名 檔名 +文件夾 資料夾 +文件擴展名 副檔名 +文字處理 文書處理 +文本 文字 +文檔 文件 文莱 汶萊 斯威士蘭 史瓦濟蘭 斯洛文尼亞 斯洛維尼亞 新西蘭 紐西蘭 方便麵 速食麵 +映射 對映 +時分多址 分時多重進接 +時分複用 分時多工 +時鐘頻率 時脈頻率 +晶閘管 閘流體 +智能 智慧 +最終用戶 終端使用者 +有損壓縮 有失真壓縮 服務器 伺服器 +本地代碼 原生代碼 +析構函數 解構函式 +枚舉 列舉 +查看 檢視 格林納達 格瑞那達 格魯吉亞 喬治亞 +桌面型 桌上型 +構造函數 建構函式 +模塊 模組 +模擬 模擬 類比 +模擬電子 類比電子 +模擬電路 類比電路 權限 許可權 +歐拉 尤拉 +正則表達式 正規表示式 +死機 宕機 +殺毒 防毒 +比特 位元 +比特率 位元率 毛里塔尼亞 茅利塔尼亞 毛里求斯 模里西斯 -毛里裘斯 模里西斯 沙特阿拉伯 沙烏地阿拉伯 +波分複用 波長分波多工 波斯尼亞黑塞哥維那 波士尼亞赫塞哥維納 津巴布韋 辛巴威 洪都拉斯 宏都拉斯 +消息 訊息 消息 +源代碼 原始碼 +源文件 原始檔 +溢出 溢位 溫納圖萬 那杜 +演示文稿 簡報 +激光 鐳射 +激活 啟用 烏茲別克斯坦 烏茲別克 -特立尼達和多巴哥 千里達托貝哥 -特立尼達和托巴哥 千里達托貝哥 +無損壓縮 無失真壓縮 +物理内存 實體記憶體 +物理地址 實體地址 +特立尼達和多巴哥 千里達及托巴哥 +狀態欄 狀態列 瑙魯 諾魯 瓦努阿圖 萬那杜 +用戶 使用者 +界面 介面 異步 非同步 +登錄 登入 +發佈 釋出 +皮膚 面板 盤片 碟片 +盤符 碟符 盧旺達 盧安達 +目標代碼 目的碼 +相冊 相簿 +矢量 向量 +知識產權 智慧財產權 短信 簡訊 -短訊 簡訊 硅 矽 硬件 硬體 硬盤 硬碟 +碼分多址 分碼多重進接 +碼率 位元速率 磁盤 磁碟 磁道 磁軌 +社區 社羣 社區 科摩羅 葛摩 科特迪瓦 象牙海岸 +移動硬盤 行動硬碟 +移動通信 行動通訊 移動電話 行動電話 +程序 程式 +程序員 程式設計師 +空分多址 分空間多重進接 +空分複用 空間多工 突尼斯 突尼西亞 +窗口 視窗 端口 埠 +筆記本電腦 膝上型電腦 算子 運算元 算法 演算法 +範式 正規化 +粘貼 貼上 粘貼 +紅心大戰 傷心小棧 索馬里 索馬利亞 -網路 網路 +組件 元件 +綁定 繫結 +網上鄰居 網路上的芳鄰 +網吧 網咖 +網絡 網路 +網關 閘道器 +線程 執行緒 +編程 程式設計 +編程語言 程式語言 +緩存 快取 +縮略圖 縮圖 +縮進 縮排 總線 匯流排 缺省 預設 老撾 寮國 -聖吉斯納域斯 聖克里斯多福及尼維斯 聖基茨和尼維斯 聖克里斯多福及尼維斯 聖文森特和格林納丁斯 聖文森及格瑞那丁 聖盧西亞 聖露西亞 聖馬力諾 聖馬利諾 聲卡 音效卡 肯尼亞 肯亞 -肯雅 肯亞 脫機 離線 +腳本 指令碼 +臺式機 桌上型電腦 航天飛機 太空梭 芯片 晶片 莫桑比克 莫三比克 +菜單 選單 菜單 萊索托 賴索托 +萬維網 全球資訊網 +藍牙 藍芽 蘇裏南 蘇利南 +虛函數 虛擬函式 +虛擬機 虛擬機器 +表達式 表示式 +複印 影印 +複選按鈕 覈取按鈕 +複選框 覈取方塊 +視圖 檢視 +視頻 視訊 +解釋器 直譯器 +觸摸屏 觸控式螢幕 +計算機安全 電腦保安 +計算機科學 電腦科學 +訪問 訪問 存取 +設備 裝置 +設置 設定 +註冊機 序號產生器 +註銷 登出 詞組 片語 +調制 調變 +調度 排程 +調用 呼叫 +調色板 調色盤 調製解調器 數據機 +調試 偵錯 +調試器 偵錯程式 變量 變數 貝寧 貝南 贊比亞 尚比亞 @@ -151,12 +354,57 @@ 軟件 軟體 軟驅 軟碟機 輔音 子音 +通信 通訊 +連接 連線 進制 進位制 +進程 程序 進程 +過程式編程 程序式程式設計 +遞歸 遞迴 +遠程 遠端 +適配器 介面卡 +邏輯門 邏輯閘 +采样率 取樣率 +重命名 重新命名 +重裝 重灌 +重載 過載 +金屬氧化物半導體 金氧半導體 +錄像 錄影 +鏈接 連結 +鏈表 連結串列 +鏡像 映象 +門戶網站 入口網站 +門電路 閘電路 閃存 快閃記憶體 +關係數據庫 關聯式資料庫 阿塞拜疆 亞塞拜然 阿拉伯聯合酋長國 阿拉伯聯合大公國 +隊列 佇列 +集成 整合 +集成電路 積體電路 +雲存儲 雲端儲存 +雲計算 雲端計算 +面向對象 物件導向 +面向過程 程序導向 +音頻 音訊 +頁眉 頁首 +頁腳 頁尾 +頭文件 標頭檔案 +頻分多址 分頻多重進接 +頻分複用 分頻多工 +類模板 類别範本 +顯像管 映象管 顯卡 顯示卡 +顯存 視訊記憶體 +首席信息官 資訊長 +首席執行官 執行長 +首席技術官 技術長 +首席運營官 營運長 +香農 夏農 馬爾代夫 馬爾地夫 馬里共和國 馬利共和國 +高端 高階 進階 +高級 高階 進階 高級 +高速緩存 快取記憶體 默認值 預設值 +點擊 點選 鼠標 滑鼠 diff --git a/data/tw/to_tw_variants.txt b/data/tw/to_tw_variants.txt index f1fb0f9..73cea60 100644 --- a/data/tw/to_tw_variants.txt +++ b/data/tw/to_tw_variants.txt @@ -19,3 +19,5 @@ 鷄 雞 麪 麵 麯 麴 +覈 核 +峯 峰 diff --git a/data/tw/tw-it.txt b/data/tw/tw-it.txt index 6a657d8..dc4858b 100644 --- a/data/tw/tw-it.txt +++ b/data/tw/tw-it.txt @@ -1,68 +1,321 @@ -缺省 預設 -默認值 預設值 -串行 串列 -以太網 乙太網 -位圖 點陣圖 -光標 游標 -光盤 光碟 -光驅 光碟機 -全角 全形 -加載 載入 -半角 半形 -變量 變數 -脫機 離線 -聲卡 音效卡 -顯卡 顯示卡 -字庫 字型檔 -字段 欄位 -字符 字元 -字符集 字符集 -存盤 存檔 -保存 儲存 -尋址 定址 -異步 非同步 -總線 匯流排 -接口 介面 -控件 控制項 -權限 許可權 -盤片 碟片 -硬盤 硬碟 -磁盤 磁碟 -磁道 磁軌 -端口 埠 -算子 運算元 -算法 演算法 -芯片 晶片 -軟驅 軟碟機 -閃存 快閃記憶體 -鼠標 滑鼠 -進制 進位制 -交互式 互動式 -仿真 模擬 -優先級 優先順序 -傳感 感測 -便攜式 攜帶型 -信息 資訊 -信息論 資訊理論 -寫保護 防寫 -分辨率 解析度 -服務器 伺服器 -網路 網路 -局域網 區域網 -互聯網 網際網路 -掃描儀 掃瞄器 -寬帶 寬頻 -數據 資料 -數據庫 資料庫 -調製解調器 數據機 -打印 列印 -打印机 印表機 -字節 位元組 -軟件 軟體 -硬件 硬體 -二極管 二極體 -三極管 三極體 -人工智能 人工智慧 -航天飛機 太空梭 -移動電話 行動電話 -短信 簡訊 \ No newline at end of file +PN結 PN接面 +SQL注入 SQL隱碼攻擊 +SQL注入攻擊 SQL隱碼攻擊 +三極管 三極體 +下拉列表 下拉選單 +並行計算 平行計算 +中間件 中介軟體 +串口 串列埠 +串行 序列 +串行端口 串列埠 +主引導記錄 主開機記錄 +主板 主機板 +二極管 二極體 +互聯網 網際網路 +交互 互動 +交互式 互動式 +人工智能 人工智慧 +代碼 程式碼 代碼 +代碼頁 內碼表 +以太網 乙太網 +任務欄 工作列 +任務管理器 工作管理員 +仿真 模擬 +位圖 點陣圖 +低級 低階 低級 +便攜式 行動式 攜帶型 +保存 儲存 +信噪比 訊雜比 +信息 資訊 +信息安全 資訊保安 +信息技術 資訊科技 +信息論 資訊理論 +信號 訊號 信號 +信道 通道 +傳感 感測 +像素 畫素 +僞代碼 虛擬碼 +優先級 優先順序 +元數據 後設資料 +元編程 超程式設計 +光標 游標 +光盤 光碟 +光驅 光碟機 +內核 核心 +內置 內建 +內聯函數 行內函數 +全角 全形 +兼容 相容 +冒泡排序 氣泡跑需 +函數式編程 函數語言程式設計 +刀片服務器 刀鋒伺服器 +分佈式 分散式 +分辨率 解析度 +刷新 重新整理 +刻錄 燒錄 +前綴 字首 +剪切 剪下 +剪貼板 剪貼簿 +加載 載入 +半角 半形 +博客 部落格 +卸載 解除安裝 +參數表 參數列 +句柄 控制代碼 +可視化 視覺化 +呼叫轉移 來電轉駁 +命令式編程 指令式程式設計 +命令行 命令列 +命名空間 名稱空間 +哈希 雜湊 +單片機 微控制器 +回調 回撥 +圖像 影象 +圖標 圖示 +在線 線上 +地址 地址 位址 +地址欄 位址列 +城域王 都會網路 +壁紙 桌布 壁紙 +外置 外接 +外鍵 外來鍵 +多任務 多工 +多態 多型 +多線程 多執行緒 +字庫 字型檔 +字段 欄位 +字符 字元 +字符集 字符集 +字節 位元組 +字體 字型 +存盤 存檔 +宏內核 單核心 +密鑰 金鑰 +實例 例項 實例 +實模式 真實模式 +審覈 稽覈 +寫保護 防寫 +寬帶 寬頻 +尋址 定址 +對話框 對話方塊 +對象 物件 對象 +導入 匯入 +導出 匯出 +局域網 區域網 +屏幕 螢幕 +屏蔽 遮蔽 +嵌套 巢狀 +帶寬 頻寬 +引導程序 載入程式 +彙編 彙編 組譯 +彙編語言 組合語言 +後綴 字尾 +循環 迴圈 循環 +性價比 價效比 +性能 效能 +截取 擷取 +打印 列印 +打印机 印表機 +打開 開啟 打開 +持久性 永續性 +捲積 摺積 +掃描儀 掃描器 +採樣 取樣 +接口 介面 +控件 控制項 +操作系統 作業系統 +擴展名 副檔名 +支持 支援 +支持者 支持者 +散列 雜湊 +數字 數字 數位 +數字印刷 數位印刷 +數字電子 數位電子 +數字電路 數位電路 +數據 資料 +數據倉庫 資料倉儲 +數據報 資料包 +數據庫 資料庫 +數據挖掘 資料探勘 +數據源 資料來源 +數組 陣列 +文件 檔案 +文件名 檔名 +文件夾 資料夾 +文件擴展名 副檔名 +文字處理 文書處理 +文本 文字 +文檔 文件 +映射 對映 +時分多址 分時多重進接 +時分複用 分時多工 +時鐘頻率 時脈頻率 +晶閘管 閘流體 +智能 智慧 +最終用戶 終端使用者 +有損壓縮 有失真壓縮 +服務器 伺服器 +本地代碼 原生代碼 +析構函數 解構函式 +枚舉 列舉 +查看 檢視 +桌面型 桌上型 +構造函數 建構函式 +模塊 模組 +模擬 模擬 類比 +模擬電子 類比電子 +模擬電路 類比電路 +權限 許可權 +正則表達式 正規表示式 +死機 宕機 +殺毒 防毒 +比特 位元 +比特率 位元率 +波分複用 波長分波多工 +消息 訊息 消息 +源代碼 原始碼 +源文件 原始檔 +溢出 溢位 +演示文稿 簡報 +激光 鐳射 +激活 啟用 +無損壓縮 無失真壓縮 +物理内存 實體記憶體 +物理地址 實體地址 +狀態欄 狀態列 +用戶 使用者 +界面 介面 +異步 非同步 +登錄 登入 +發佈 釋出 +皮膚 面板 +盤片 碟片 +盤符 碟符 +目標代碼 目的碼 +相冊 相簿 +矢量 向量 +知識產權 智慧財產權 +短信 簡訊 +硬件 硬體 +硬盤 硬碟 +碼分多址 分碼多重進接 +碼率 位元速率 +磁盤 磁碟 +磁道 磁軌 +社區 社羣 社區 +移動硬盤 行動硬碟 +移動通信 行動通訊 +移動電話 行動電話 +程序 程式 +程序員 程式設計師 +空分多址 分空間多重進接 +空分複用 空間多工 +窗口 視窗 +端口 埠 +筆記本電腦 膝上型電腦 +算子 運算元 +算法 演算法 +範式 正規化 +粘貼 貼上 粘貼 +紅心大戰 傷心小棧 +組件 元件 +綁定 繫結 +網上鄰居 網路上的芳鄰 +網吧 網咖 +網絡 網路 +網關 閘道器 +線程 執行緒 +編程 程式設計 +編程語言 程式語言 +緩存 快取 +縮略圖 縮圖 +縮進 縮排 +總線 匯流排 +缺省 預設 +聲卡 音效卡 +脫機 離線 +腳本 指令碼 +臺式機 桌上型電腦 +航天飛機 太空梭 +芯片 晶片 +菜單 選單 菜單 +萬維網 全球資訊網 +藍牙 藍芽 +虛函數 虛擬函式 +虛擬機 虛擬機器 +表達式 表示式 +複印 影印 +複選按鈕 覈取按鈕 +複選框 覈取方塊 +視圖 檢視 +視頻 視訊 +解釋器 直譯器 +觸摸屏 觸控式螢幕 +計算機安全 電腦保安 +計算機科學 電腦科學 +訪問 訪問 存取 +設備 裝置 +設置 設定 +註冊機 序號產生器 +註銷 登出 +調制 調變 +調度 排程 +調用 呼叫 +調色板 調色盤 +調製解調器 數據機 +調試 偵錯 +調試器 偵錯程式 +變量 變數 +軟件 軟體 +軟驅 軟碟機 +通信 通訊 +連接 連線 +進制 進位制 +進程 程序 進程 +過程式編程 程序式程式設計 +遞歸 遞迴 +遠程 遠端 +適配器 介面卡 +邏輯門 邏輯閘 +采样率 取樣率 +重命名 重新命名 +重裝 重灌 +重載 過載 +金屬氧化物半導體 金氧半導體 +錄像 錄影 +鏈接 連結 +鏈表 連結串列 +鏡像 映象 +門戶網站 入口網站 +門電路 閘電路 +閃存 快閃記憶體 +關係數據庫 關聯式資料庫 +隊列 佇列 +集成 整合 +集成電路 積體電路 +雲存儲 雲端儲存 +雲計算 雲端計算 +面向對象 物件導向 +面向過程 程序導向 +音頻 音訊 +頁眉 頁首 +頁腳 頁尾 +頭文件 標頭檔案 +頻分多址 分頻多重進接 +頻分複用 分頻多工 +類模板 類别範本 +顯像管 映象管 +顯卡 顯示卡 +顯存 視訊記憶體 +首席信息官 資訊長 +首席執行官 執行長 +首席技術官 技術長 +首席運營官 營運長 +高端 高階 進階 +高級 高階 進階 高級 +高速緩存 快取記憶體 +默認值 預設值 +點擊 點選 +鼠標 滑鼠 +晶體管 電晶體 +場效應管 場效電晶體 \ No newline at end of file diff --git a/data/tw/tw-name.txt b/data/tw/tw-name.txt index e7ef486..86a97cb 100644 --- a/data/tw/tw-name.txt +++ b/data/tw/tw-name.txt @@ -1,77 +1,81 @@ -烏茲別克斯坦 烏茲別克 -乍得 查德 -也門 葉門 -伯利茲 貝里斯 -佛得角 維德角 -克羅地亞 克羅埃西亞 -岡比亞 甘比亞 -幾內亞比紹 幾內亞比索 -列支敦士登 列支敦斯登 -利比里亞 賴比瑞亞 -加納 迦納 -加蓬 加彭 -博茨瓦納 波札那 -卡塔爾 卡達 -盧旺達 盧安達 -危地馬拉 瓜地馬拉 -厄瓜多爾 厄瓜多 -厄立特里亞 厄利垂亞 -吉布堤 吉布地 -哈萨克斯坦 哈薩克 -哥斯達黎加 哥斯大黎加 -圖瓦盧 吐瓦魯 -土庫曼斯坦 土庫曼 -聖盧西亞 聖露西亞 -聖基茨和尼維斯 聖克里斯多福及尼維斯 -聖文森特和格林納丁斯 聖文森及格瑞那丁 -聖馬力諾 聖馬利諾 -圭亞那 蓋亞那 -坦桑尼亞 坦尚尼亞 -埃塞俄比亞 衣索比亞 -基里巴斯 吉里巴斯 -塔吉克斯坦 塔吉克 -塞拉利昂 獅子山 -塞浦路斯 塞普勒斯 -塞舌爾 塞席爾 -多米尼加 多明尼加 -安提瓜和巴布達 安地卡及巴布達 -尼日利亞 奈及利亞 -尼日爾 尼日 -巴巴多斯 巴貝多 -巴布亞新幾内亚 巴布亞紐幾內亞 -布基納法索 布吉納法索 -布隆迪 蒲隆地 -帕劳 帛琉 -意大利 義大利 -所羅門羣島 索羅門羣島 -文莱 汶萊 -斯威士蘭 史瓦濟蘭 -斯洛文尼亞 斯洛維尼亞 -新西蘭 紐西蘭 -格林納達 格瑞那達 -格魯吉亞 喬治亞 -毛里塔尼亞 茅利塔尼亞 -毛里求斯 模里西斯 -沙特阿拉伯 沙烏地阿拉伯 -波斯尼亞黑塞哥維那 波士尼亞赫塞哥維納 -津巴布韋 辛巴威 -洪都拉斯 宏都拉斯 -特立尼達和多巴哥 千里達及托巴哥 -瑙魯 諾魯 -瓦努阿圖 萬那杜 -溫納圖萬 那杜 -科摩羅 葛摩 -科特迪瓦 象牙海岸 -突尼斯 突尼西亞 -索馬里 索馬利亞 -老撾 寮國 -肯尼亞 肯亞 -蘇裏南 蘇利南 -莫桑比克 莫三比克 -萊索托 賴索托 -貝寧 貝南 -贊比亞 尚比亞 -阿塞拜疆 亞塞拜然 -阿拉伯聯合酋長國 阿拉伯聯合大公國 -馬爾代夫 馬爾地夫 -馬里共和國 馬利共和國 \ No newline at end of file +乍得 查德 +也門 葉門 +仙童半導體 快捷半導體 +伯利茲 貝里斯 +佛得角 維德角 +傅里葉 傅立葉 +克羅地亞 克羅埃西亞 +列支敦士登 列支敦斯登 +利比里亞 賴比瑞亞 +加納 迦納 +加蓬 加彭 +博茨瓦納 波札那 +卡塔爾 卡達 +危地馬拉 瓜地馬拉 +厄瓜多爾 厄瓜多 +厄立特里亞 厄利垂亞 +吉布堤 吉布地 +哈萨克斯坦 哈薩克 +哥斯達黎加 哥斯大黎加 +圖瓦盧 吐瓦魯 +土庫曼斯坦 土庫曼 +圭亞那 蓋亞那 +坦桑尼亞 坦尚尼亞 +埃塞俄比亞 衣索比亞 +基里巴斯 吉里巴斯 +塔吉克斯坦 塔吉克 +塞拉利昂 獅子山 +塞浦路斯 塞普勒斯 +塞舌爾 塞席爾 +多米尼加 多明尼加 +安提瓜和巴布達 安地卡及巴布達 +尼日利亞 奈及利亞 +尼日爾 尼日 +岡比亞 甘比亞 +巴巴多斯 巴貝多 +巴布亞新幾内亚 巴布亞紐幾內亞 +布基納法索 布吉納法索 +布隆迪 蒲隆地 +帕劳 帛琉 +幾內亞比紹 幾內亞比索 +意大利 義大利 +所羅門羣島 索羅門羣島 +文莱 汶萊 +斯威士蘭 史瓦濟蘭 +斯洛文尼亞 斯洛維尼亞 +新西蘭 紐西蘭 +格林納達 格瑞那達 +格魯吉亞 喬治亞 +歐拉 尤拉 +毛里塔尼亞 茅利塔尼亞 +毛里求斯 模里西斯 +沙特阿拉伯 沙烏地阿拉伯 +波斯尼亞黑塞哥維那 波士尼亞赫塞哥維納 +津巴布韋 辛巴威 +洪都拉斯 宏都拉斯 +溫納圖萬 那杜 +烏茲別克斯坦 烏茲別克 +特立尼達和多巴哥 千里達及托巴哥 +瑙魯 諾魯 +瓦努阿圖 萬那杜 +盧旺達 盧安達 +科摩羅 葛摩 +科特迪瓦 象牙海岸 +突尼斯 突尼西亞 +索馬里 索馬利亞 +老撾 寮國 +聖基茨和尼維斯 聖克里斯多福及尼維斯 +聖文森特和格林納丁斯 聖文森及格瑞那丁 +聖盧西亞 聖露西亞 +聖馬力諾 聖馬利諾 +肯尼亞 肯亞 +莫桑比克 莫三比克 +萊索托 賴索托 +蘇裏南 蘇利南 +貝寧 貝南 +贊比亞 尚比亞 +阿塞拜疆 亞塞拜然 +阿拉伯聯合酋長國 阿拉伯聯合大公國 +香農 夏農 +馬爾代夫 馬爾地夫 +馬里共和國 馬利共和國 diff --git a/gypi/configs.gypi b/gypi/configs.gypi new file mode 100644 index 0000000..d7d82d4 --- /dev/null +++ b/gypi/configs.gypi @@ -0,0 +1,25 @@ +{ + "targets": [{ + "target_name": "configs", + "type": "none", + "copies": [{ + "destination": "<(PRODUCT_DIR)", + "files": [ + "../data/config/mix2zhs.ini", + "../data/config/mix2zht.ini", + "../data/config/zhs2zht.ini", + "../data/config/zhs2zhtw_p.ini", + "../data/config/zhs2zhtw_v.ini", + "../data/config/zhs2zhtw_vp.ini", + "../data/config/zht2zhs.ini", + "../data/config/zht2zhtw_p.ini", + "../data/config/zht2zhtw_v.ini", + "../data/config/zht2zhtw_vp.ini", + "../data/config/zhtw2zhcn_s.ini", + "../data/config/zhtw2zhcn_t.ini", + "../data/config/zhtw2zhs.ini", + "../data/config/zhtw2zht.ini" + ] + }] + }] +} diff --git a/gypi/dicts.gypi b/gypi/dicts.gypi new file mode 100644 index 0000000..b30b7b2 --- /dev/null +++ b/gypi/dicts.gypi @@ -0,0 +1,60 @@ +{ + "includes": [ + "opencc_dict.gypi", + ], + "targets": [{ + "target_name": "dicts", + "type": "none", + "variables": { + "cmd": "<(PRODUCT_DIR)/opencc_dict", + "input_prefix": "data/", + "output_prefix": "<(PRODUCT_DIR)/" + }, + "copies": [{ + "destination": "<(PRODUCT_DIR)", + "files": [ + "../data/tw/to_tw_variants.txt", + "../data/tw/to_tw_phrases.txt", + "../data/tw/from_tw_variants.txt", + "../data/tw/from_tw_phrases.txt", + "../data/cn/to_cn_phrases.txt" + ] + }], + "actions": [{ + "action_name": "simp_to_trad_characters", + "variables": { + "input": "<(input_prefix)simp_to_trad/characters.txt", + }, + "inputs": ["<(cmd)", "<(input)"], + "outputs": ["<(output_prefix)simp_to_trad_characters.ocd"], + "action": ["<(cmd)", "-i", "<(input)", "-o", "<@(_outputs)"] + }, { + "action_name": "simp_to_trad_phrases", + "variables": { + "input": "<(input_prefix)simp_to_trad/phrases.txt", + }, + "inputs": ["<(cmd)", "<(input)"], + "outputs": ["<(output_prefix)simp_to_trad_phrases.ocd"], + "action": ["<(cmd)", "-i", "<(input)", "-o", "<@(_outputs)"] + }, { + "action_name": "trad_to_simp_characters", + "variables": { + "input": "<(input_prefix)trad_to_simp/characters.txt", + }, + "inputs": ["<(cmd)", "<(input)"], + "outputs": ["<(output_prefix)trad_to_simp_characters.ocd"], + "action": ["<(cmd)", "-i", "<(input)", "-o", "<@(_outputs)"] + }, { + "action_name": "trad_to_simp_phrases", + "variables": { + "input": "<(input_prefix)trad_to_simp/phrases.txt", + }, + "inputs": ["<(cmd)", "<(input)"], + "outputs": ["<(output_prefix)trad_to_simp_phrases.ocd"], + "action": ["<(cmd)", "-i", "<(input)", "-o", "<@(_outputs)"] + }], + "dependencies": [ + "opencc_dict" + ] + }] +} diff --git a/gypi/global.gypi b/gypi/global.gypi new file mode 100644 index 0000000..9ec1f8b --- /dev/null +++ b/gypi/global.gypi @@ -0,0 +1,11 @@ +{ + "variables": { + "opencc_version": "0.4.0" + }, + "target_defaults": { + "defines": [ + "VERSION=\"<(opencc_version)\"", + "PKGDATADIR=\"\"" + ] + } +} diff --git a/gypi/opencc_dict.gypi b/gypi/opencc_dict.gypi new file mode 100644 index 0000000..65de6a2 --- /dev/null +++ b/gypi/opencc_dict.gypi @@ -0,0 +1,17 @@ +{ + "targets": [{ + "target_name": "opencc_dict", + "type": "executable", + "sources": [ + "../src/tools/opencc_dict.c", + "../src/encoding.c", + "../src/utils.c", + "../src/dictionary_group.c", + "../src/dictionary_set.c", + "../src/config_reader.c", + "../src/dictionary/abstract.c", + "../src/dictionary/datrie.c", + "../src/dictionary/text.c" + ] + }] +} diff --git a/node/binding.cc b/node/binding.cc new file mode 100644 index 0000000..2e38dad --- /dev/null +++ b/node/binding.cc @@ -0,0 +1,163 @@ +#include +#include +#include +#include "../src/opencc.h" + +using namespace v8; + +char* ToUtf8String(const Local& str) { + char* utf8 = new char[str->Utf8Length() + 1]; + utf8[str->Utf8Length()] = '\0'; + str->WriteUtf8(utf8); + return utf8; +} + +class Opencc : public node::ObjectWrap { + struct ConvertRequest { + Opencc* opencc_instance; + char* input; + char* output; + Persistent callback; + }; + public: + explicit Opencc(const char * config_file) { + handler_ = opencc_open(config_file); + } + + virtual ~Opencc() { + if (handler_ != (opencc_t) -1) + opencc_close(handler_); + } + + operator bool() const { + return handler_ != (opencc_t) -1; + } + + static Handle New(const Arguments& args) { + HandleScope scope; + Opencc* opencc_instance; + + if (args.Length() >= 1 && args[0]->IsString()) { + char* config_file = ToUtf8String(args[0]->ToString()); + opencc_instance = new Opencc(config_file); + delete [] config_file; + } else { + const char* config_file = OPENCC_DEFAULT_CONFIG_SIMP_TO_TRAD; + opencc_instance = new Opencc(config_file); + } + + if (!*opencc_instance) { + ThrowException(Exception::Error( + String::New("Can not create opencc instance"))); + return scope.Close(Undefined()); + } + opencc_instance->Wrap(args.This()); + return args.This(); + } + + static Handle Convert(const Arguments& args) { + HandleScope scope; + if (args.Length() < 2 || !args[0]->IsString() || !args[1]->IsFunction()) { + ThrowException(Exception::TypeError(String::New("Wrong arguments"))); + return scope.Close(Undefined()); + } + + ConvertRequest* conv_data = new ConvertRequest; + conv_data->opencc_instance = ObjectWrap::Unwrap(args.This()); + conv_data->input = ToUtf8String(args[0]->ToString()); + conv_data->callback = Persistent::New(Local::Cast(args[1])); + uv_work_t* req = new uv_work_t; + req->data = conv_data; + uv_queue_work(uv_default_loop(), req, DoConnect, AfterConvert); + + return Undefined(); + } + + static void DoConnect(uv_work_t* req) { + ConvertRequest* conv_data = static_cast(req->data); + opencc_t opencc_handler = conv_data->opencc_instance->handler_; + conv_data->output = opencc_convert_utf8(opencc_handler, conv_data->input, (size_t) -1); + } + + static void AfterConvert(uv_work_t* req) { + HandleScope scope; + ConvertRequest* conv_data = static_cast(req->data); + Local converted = String::New(conv_data->output); + const unsigned argc = 2; + Local argv[argc] = { + Local::New(Undefined()), + Local::New(converted) + }; + conv_data->callback->Call(Context::GetCurrent()->Global(), argc, argv); + conv_data->callback.Dispose(); + delete[] conv_data->input; + delete[] conv_data->output; + delete conv_data; + delete req; + } + + static Handle ConvertSync(const Arguments& args) { + HandleScope scope; + if (args.Length() < 1 || !args[0]->IsString()) { + ThrowException(Exception::TypeError(String::New("Wrong arguments"))); + return scope.Close(Undefined()); + } + + Opencc* opencc_instance = ObjectWrap::Unwrap(args.This()); + opencc_t opencc_handler = opencc_instance->handler_; + char* input = ToUtf8String(args[0]->ToString()); + char* output = opencc_convert_utf8(opencc_handler, input, (size_t) -1); + + Local converted = String::New(output); + delete[] input; + delete[] output; + return scope.Close(converted); + } + + static Handle SetConversionMode(const Arguments& args) { + HandleScope scope; + if (args.Length() < 1 || !args[0]->IsInt32()) { + ThrowException(Exception::TypeError(String::New("Wrong arguments"))); + return scope.Close(Undefined()); + } + + Opencc* opencc_instance = ObjectWrap::Unwrap(args.This()); + opencc_t opencc_handler = opencc_instance->handler_; + int conversion_mode = args[0]->ToInt32()->Value(); + if (conversion_mode < 0 || conversion_mode > 2) { + ThrowException(Exception::Error( + String::New("conversion_mode must between 0 and 2"))); + return scope.Close(Undefined()); + } + + opencc_set_conversion_mode(opencc_handler, + (opencc_conversion_mode) conversion_mode); + return scope.Close(Boolean::New(true)); + } + + static void init(Handle target) { + // Prepare constructor template + Local tpl = FunctionTemplate::New(Opencc::New); + tpl->SetClassName(String::NewSymbol("Opencc")); + tpl->InstanceTemplate()->SetInternalFieldCount(1); + // Prototype + tpl->PrototypeTemplate()->Set(String::NewSymbol("convert"), + FunctionTemplate::New(Convert)->GetFunction()); + tpl->PrototypeTemplate()->Set(String::NewSymbol("convertSync"), + FunctionTemplate::New(ConvertSync)->GetFunction()); + tpl->PrototypeTemplate()->Set(String::NewSymbol("setConversionMode"), + FunctionTemplate::New(SetConversionMode)->GetFunction()); + // Constructor + Persistent constructor = Persistent::New( + tpl->GetFunction()); + target->Set(String::NewSymbol("Opencc"), constructor); + } + + opencc_t handler_; +}; + +void init(Handle target) { + Opencc::init(target); +} + +NODE_MODULE(binding, init); diff --git a/node/demo.js b/node/demo.js new file mode 100644 index 0000000..7cfe243 --- /dev/null +++ b/node/demo.js @@ -0,0 +1,11 @@ +var OpenCC = require('./opencc'); + +var opencc = new OpenCC('zhs2zht.ini'); +opencc.setConversionMode(OpenCC.CONVERSION_FAST); + +var converted = opencc.convertSync("汉字"); +console.log(converted); + +opencc.convert("汉字", function (err, converted) { + console.log(converted); +}); diff --git a/node/opencc.js b/node/opencc.js new file mode 100644 index 0000000..0056a4e --- /dev/null +++ b/node/opencc.js @@ -0,0 +1,36 @@ +var path = require('path'); +var binding = require('../build/Release/binding'); + +var assetsPath = path.resolve(__dirname, '../build/Release'); +var getConfigPath = function (config) { + var configPath = config; + if (config[0] !== '/' && config[1] !== ':') { + // Resolve relative path + configPath = path.join(assetsPath, config); + } + return configPath; +}; + +var OpenCC = module.exports = function (config) { + if (!config) { + config = 'zhs2zht.ini'; + } + config = getConfigPath(config); + this.handler = new binding.Opencc(config); +}; + +OpenCC.CONVERSION_FAST = 0; +OpenCC.CONVERSION_SEGMENT_ONLY = 1; +OpenCC.CONVERSION_LIST_CANDIDATES = 2; + +OpenCC.prototype.convert = function (input, callback) { + return this.handler.convert(input.toString(), callback); +}; + +OpenCC.prototype.convertSync = function (input) { + return this.handler.convertSync(input.toString()); +}; + +OpenCC.prototype.setConversionMode = function (conversionMode) { + return this.handler.setConversionMode(conversionMode); +}; diff --git a/node/test.js b/node/test.js new file mode 100644 index 0000000..fce41b5 --- /dev/null +++ b/node/test.js @@ -0,0 +1,64 @@ +var assert = require('assert'); +var fs = require('fs'); +var OpenCC = require('./opencc'); + +var configs = [ + 'zhs2zht', + 'zht2zhs', + 'mix2zht', + 'mix2zhs', + 'zhs2zhtw_p', + 'zhs2zhtw_vp', + 'zhtw2zhcn_t', + 'zhtw2zhcn_s', +]; + +var testSync = function (config, done) { + var inputName = 'test/testcases/' + config + '.in'; + var outputName = 'test/testcases/' + config + '.ans'; + var configName = config + '.ini'; + var opencc = new OpenCC(configName); + fs.readFile(inputName, 'utf-8', function (err, text) { + if (err) return done(err); + var converted = opencc.convertSync(text); + fs.readFile(outputName, 'utf-8', function (err, answer) { + if (err) return done(err); + assert.equal(converted, answer); + done(); + }); + }); +}; + +var testAsync = function (config, done) { + var inputName = 'test/testcases/' + config + '.in'; + var outputName = 'test/testcases/' + config + '.ans'; + var configName = config + '.ini'; + var opencc = new OpenCC(configName); + fs.readFile(inputName, 'utf-8', function (err, text) { + if (err) return done(err); + opencc.convert(text, function (err, converted) { + if (err) return done(err); + fs.readFile(outputName, 'utf-8', function (err, answer) { + if (err) return done(err); + assert.equal(converted, answer); + done(); + }); + }); + }); +}; + +describe('Sync API', function () { + configs.forEach(function (config) { + it(config, function (done) { + testSync(config, done); + }); + }); +}); + +describe('Async API', function () { + configs.forEach(function (config) { + it(config, function (done) { + testAsync(config, done); + }); + }); +}); diff --git a/opencc.gyp b/opencc.gyp new file mode 100644 index 0000000..b128229 --- /dev/null +++ b/opencc.gyp @@ -0,0 +1,39 @@ +{ + "includes": [ + "gypi/global.gypi", + "gypi/configs.gypi", + "gypi/dicts.gypi", + ], + "targets": [{ + "target_name": "libopencc", + "type": "<(library)", + "sources": [ + "src/config_reader.c", + "src/converter.c", + "src/dictionary_group.c", + "src/dictionary_set.c", + "src/encoding.c", + "src/utils.c", + "src/opencc.c", + "src/dictionary/abstract.c", + "src/dictionary/datrie.c", + "src/dictionary/text.c" + ], + "conditions": [ + ["OS=='linux'", { + "cflags": [ + "-fPIC" + ] + }] + ] + }, { + "target_name": "opencc", + "type": "executable", + "sources": [ + "src/tools/opencc.c" + ], + "dependencies": [ + "libopencc" + ] + }] +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..4bc8a1f --- /dev/null +++ b/package.json @@ -0,0 +1,28 @@ +{ + "name": "opencc", + "version": "0.4.0", + "description": "A project for conversion between Traditional and Simplified Chinese", + "author": "BYVoid ", + "license": "Apache", + "main": "node/opencc.js", + "scripts": { + "test": "mocha -R spec node/test.js" + }, + "repository": { + "type": "git", + "url": "git://github.com/BYVoid/OpenCC.git" + }, + "bugs": { + "url": "https://code.google.com/p/opencc/issues/entry" + }, + "keywords": [ + "opencc", + "Chinese", + "conversion", + "Simplified Chinese", + "Traditional Chinese" + ], + "devDependencies": { + "mocha": "1.8.1" + } +} diff --git a/release.sh b/release.sh index 8575f83..64c471b 100755 --- a/release.sh +++ b/release.sh @@ -6,4 +6,5 @@ mkdir -p release \ -DCMAKE_INSTALL_PREFIX=/usr \ .. \ && make \ -&& make test +&& make test \ +&& make package_source diff --git a/src/common.h b/src/common.h new file mode 100644 index 0000000..2b3a01a --- /dev/null +++ b/src/common.h @@ -0,0 +1,54 @@ +/* +* Open Chinese Convert +* +* Copyright 2013 BYVoid +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef __COMMON_H_ +#define __COMMON_H_ + +#include +#include +#include +#include + +#include "opencc_types.h" + +#define FALSE (0) +#define TRUE (!(0)) +#define INFINITY_INT ((~0U)>>1) + +#ifndef BIG_ENDIAN +# define BIG_ENDIAN (0) +#endif + +#ifndef LITTLE_ENDIAN +# define LITTLE_ENDIAN (1) +#endif + +#ifdef ENABLE_GETTEXT +# include +# include +# define _(STRING) dgettext(PACKAGE_NAME, STRING) +#else +# define _(STRING) STRING +#endif + +typedef void * converter_t; +typedef void * config_t; +typedef void * dictionary_group_t; +typedef void * dictionary_set_t; + +#endif \ No newline at end of file diff --git a/src/config_reader.c b/src/config_reader.c index a357f1a..9ac84ed 100644 --- a/src/config_reader.c +++ b/src/config_reader.c @@ -18,6 +18,7 @@ #include "config_reader.h" #include "dictionary_set.h" +#include "dictionary_group.h" #define BUFFER_SIZE 8192 #define DICTIONARY_MAX_COUNT 1024 @@ -37,7 +38,7 @@ struct _config_desc char * title; char * description; dictionary_set_t dictionary_set; - + char * file_path; dictionary_buffer dicts[DICTIONARY_MAX_COUNT]; size_t dicts_count; size_t stamp; @@ -187,26 +188,17 @@ static char * parse_trim(char * str) static int parse(config_desc * config, const char * filename) { - FILE * fp = fopen(filename, "rb"); - if (!fp) - { - /* 使用 PKGDATADIR 路徑 */ - char * pkg_filename = - (char *) malloc(sizeof(char) * (strlen(filename) + strlen(PKGDATADIR) + 2)); - sprintf(pkg_filename, "%s/%s", PKGDATADIR, filename); - - fp = fopen(pkg_filename, "rb"); - if (!fp) - { - free(pkg_filename); - errnum = CONFIG_ERROR_CANNOT_ACCESS_CONFIG_FILE; - return -1; - } - free(pkg_filename); + char * path = try_open_file(filename); + if (path == NULL) { + errnum = CONFIG_ERROR_CANNOT_ACCESS_CONFIG_FILE; + return -1; } - + config->file_path = get_file_path(path); + FILE * fp = fopen(path, "r"); + assert(fp != NULL); + free(path); + skip_utf8_bom(fp); static char buff[BUFFER_SIZE]; - while (fgets(buff, BUFFER_SIZE, fp) != NULL) { char * trimed_buff = parse_trim(buff); @@ -215,9 +207,7 @@ static int parse(config_desc * config, const char * filename) /* Comment Line or empty line */ continue; } - char * key = NULL, * value = NULL; - if (parse_line(trimed_buff, &key, &value) == -1) { free(key); @@ -226,7 +216,6 @@ static int parse(config_desc * config, const char * filename) errnum = CONFIG_ERROR_PARSE; return -1; } - if (parse_property(config, key, value) == -1) { free(key); @@ -234,11 +223,9 @@ static int parse(config_desc * config, const char * filename) fclose(fp); return -1; } - free(key); free(value); } - fclose(fp); return 0; } @@ -252,7 +239,7 @@ dictionary_set_t config_get_dictionary_set(config_t t_config) dictionary_set_close(config->dictionary_set); } - config->dictionary_set = dictionary_set_open(); + config->dictionary_set = dictionary_set_open(t_config); load_dictionary(config); return config->dictionary_set; @@ -297,6 +284,7 @@ config_t config_open(const char * filename) config->dicts_count = 0; config->stamp = 0; config->dictionary_set = NULL; + config->file_path = NULL; if (parse(config, filename) == -1) { @@ -317,5 +305,12 @@ void config_close(config_t t_config) free(config->title); free(config->description); + free(config->file_path); free(config); } + +const char * config_get_file_path(config_t t_config) +{ + config_desc * config = (config_desc *) t_config; + return config->file_path; +} diff --git a/src/config_reader.h b/src/config_reader.h index c242c46..cfbb94a 100644 --- a/src/config_reader.h +++ b/src/config_reader.h @@ -19,10 +19,7 @@ #ifndef __OPENCC_CONFIG_H_ #define __OPENCC_CONFIG_H_ -#include "utils.h" -#include "dictionary_set.h" - -typedef void * config_t; +#include "common.h" typedef enum { @@ -43,4 +40,6 @@ config_error config_errno(void); void config_perror(const char * spec); +const char * config_get_file_path(config_t t_config); + #endif /* __OPENCC_CONFIG_H_ */ diff --git a/src/converter.c b/src/converter.c index a3b928c..5efd57d 100644 --- a/src/converter.c +++ b/src/converter.c @@ -16,10 +16,11 @@ * limitations under the License. */ -#include "utils.h" +#include "common.h" #include "converter.h" #include "encoding.h" #include "dictionary_set.h" +#include "dictionary_group.h" #define DELIMITER ' ' #define SEGMENT_MAXIMUM_LENGTH 0 diff --git a/src/converter.h b/src/converter.h index de12763..a679a33 100644 --- a/src/converter.h +++ b/src/converter.h @@ -19,9 +19,7 @@ #ifndef __CONVERTER_H_ #define __CONVERTER_H_ -#include "dictionary_set.h" - -typedef void * converter_t; +#include "common.h" typedef enum { diff --git a/src/dictionary/datrie.c b/src/dictionary/datrie.c index 63e49e3..246a1cc 100644 --- a/src/dictionary/datrie.c +++ b/src/dictionary/datrie.c @@ -229,13 +229,13 @@ int encode_char(ucs4_t ch) void datrie_match(const datrie_dictionary_desc * datrie_dictionary, const ucs4_t * word, size_t *match_pos, size_t *id, size_t limit) { - size_t i, p; - for (i = 0,p = 0; word[p] && (limit == 0 || p < limit) && + int i, p; + for (i = 0, p = 0; word[p] && (limit == 0 || (size_t)p < limit) && datrie_dictionary->dat[i].base != DATRIE_UNUSED; p ++) { int k = encode_char(word[p]); int j = datrie_dictionary->dat[i].base + k; - if (j < 0 || j >= datrie_dictionary->dat_item_count || datrie_dictionary->dat[j].parent != i) + if (j < 0 || (size_t)j >= datrie_dictionary->dat_item_count || datrie_dictionary->dat[j].parent != i) break; i = j; } @@ -277,12 +277,12 @@ size_t dictionary_datrie_get_all_match_lengths(dictionary_t t_dictionary, const size_t rscnt = 0; - size_t i, p; + int i, p; for (i = 0,p = 0; word[p] && datrie_dictionary->dat[i].base != DATRIE_UNUSED; p ++) { int k = encode_char(word[p]); int j = datrie_dictionary->dat[i].base + k; - if (j < 0 || j >= datrie_dictionary->dat_item_count || datrie_dictionary->dat[j].parent != i) + if (j < 0 || (size_t)j >= datrie_dictionary->dat_item_count || datrie_dictionary->dat[j].parent != i) break; i = j; diff --git a/src/dictionary/text.c b/src/dictionary/text.c index dcbb5df..a6107a7 100644 --- a/src/dictionary/text.c +++ b/src/dictionary/text.c @@ -72,7 +72,7 @@ int parse_entry(const char * buff, entry * entry_i) ); } - for (buff = ++ pbuff; *pbuff != ' ' && *pbuff != '\0' && *pbuff != '\n'; ++ pbuff) + for (buff = ++ pbuff; *pbuff != ' ' && *pbuff != '\0' && *pbuff != '\n' && *pbuff != '\r'; ++ pbuff) ; length = pbuff - buff; ucs4_buff = utf8_to_ucs4(buff, length); @@ -112,12 +112,13 @@ dictionary_t dictionary_text_open(const char * filename) static char buff[ENTRY_BUFF_SIZE]; - FILE * fp = fopen(filename,"rb"); + FILE * fp = fopen(filename,"r"); if (fp == NULL) { dictionary_text_close((dictionary_t) text_dictionary); return (dictionary_t) -1; } + skip_utf8_bom(fp); size_t i = 0; while (fgets(buff, ENTRY_BUFF_SIZE, fp)) diff --git a/src/dictionary_group.c b/src/dictionary_group.c index 4da04ff..3b43128 100644 --- a/src/dictionary_group.c +++ b/src/dictionary_group.c @@ -17,11 +17,14 @@ */ #include "dictionary_group.h" +#include "dictionary_set.h" +#include "config_reader.h" #define DICTIONARY_MAX_COUNT 128 struct _dictionary_group { + dictionary_set_t dictionary_set; size_t count; dictionary_t dicts[DICTIONARY_MAX_COUNT]; } ; @@ -29,12 +32,13 @@ typedef struct _dictionary_group dictionary_group_desc; static dictionary_error errnum = DICTIONARY_ERROR_VOID; -dictionary_group_t dictionary_group_open(void) +dictionary_group_t dictionary_group_open(dictionary_set_t t_dictionary_set) { dictionary_group_desc * dictionary_group = (dictionary_group_desc *) malloc(sizeof(dictionary_group_desc)); dictionary_group->count = 0; + dictionary_group->dictionary_set = t_dictionary_set; return dictionary_group; } @@ -50,36 +54,53 @@ void dictionary_group_close(dictionary_group_t t_dictionary) free(dictionary_group); } +static char * try_find_dictionary_with_config(dictionary_group_desc * dictionary_group, const char * filename) +{ + if (is_absolute_path(filename)) + { + return NULL; + } + /* Get config path */ + if (dictionary_group->dictionary_set == NULL) + { + return NULL; + } + config_t config = dictionary_set_get_config(dictionary_group->dictionary_set); + if (config == NULL) + { + return NULL; + } + const char * config_path = config_get_file_path(config); + if (config_path == NULL) + { + return NULL; + } + char * config_path_filename = (char *) malloc(strlen(config_path) + strlen(filename) + 3); + sprintf(config_path_filename, "%s/%s%c", config_path, filename, '\0'); + FILE * fp = fopen(config_path_filename, "r"); + if (fp) + { + fclose(fp); + return config_path_filename; + } + return NULL; +} + int dictionary_group_load(dictionary_group_t t_dictionary, const char * filename, opencc_dictionary_type type) { dictionary_group_desc * dictionary_group = (dictionary_group_desc *) t_dictionary; dictionary_t dictionary; - - FILE * fp = fopen(filename, "rb"); - if (!fp) - { - /* 使用 PKGDATADIR 路徑 */ - char * new_filename = - (char *) malloc(sizeof(char) * (strlen(filename) + strlen(PKGDATADIR) + 2)); - sprintf(new_filename, "%s/%s", PKGDATADIR, filename); - - fp = fopen(new_filename, "rb"); - if (!fp) - { - free(new_filename); + char * path = try_open_file(filename); + if (path == NULL) { + path = try_find_dictionary_with_config(dictionary_group, filename); + if (path == NULL) { errnum = DICTIONARY_ERROR_CANNOT_ACCESS_DICTFILE; return -1; } - dictionary = dictionary_open(new_filename, type); - free(new_filename); - } - else - { - dictionary = dictionary_open(filename, type); } - fclose(fp); - + dictionary = dictionary_open(path, type); + free(path); if (dictionary == (dictionary_t) -1) { errnum = DICTIONARY_ERROR_INVALID_DICT; @@ -93,7 +114,7 @@ dictionary_t dictionary_group_get_dictionary(dictionary_group_t t_dictionary, si { dictionary_group_desc * dictionary_group = (dictionary_group_desc *) t_dictionary; - if (index < 0 || index >= dictionary_group->count) + if (index >= dictionary_group->count) { errnum = DICTIONARY_ERROR_INVALID_INDEX; return (dictionary_t) -1; @@ -177,7 +198,7 @@ size_t dictionary_group_get_all_match_lengths(dictionary_group_t t_dictionary, if (i > 0 && rscnt > 1) { qsort(match_length, rscnt, sizeof(match_length[0]), qsort_int_cmp); - int j, k; + size_t j, k; for (j = 0, k = 1; k < rscnt; k ++) { if (match_length[k] != match_length[j]) @@ -218,3 +239,9 @@ void dictionary_perror(const char * spec) perr(_("Unknown")); } } + +dictionary_set_t dictionary_group_get_dictionary_set(dictionary_group_t t_dictionary) +{ + dictionary_group_desc * dictionary_group = (dictionary_group_desc *) t_dictionary; + return dictionary_group->dictionary_set; +} diff --git a/src/dictionary_group.h b/src/dictionary_group.h index 3911574..692a401 100644 --- a/src/dictionary_group.h +++ b/src/dictionary_group.h @@ -19,11 +19,9 @@ #ifndef __DICTIONARY_GROUP_H_ #define __DICTIONARY_GROUP_H_ -#include "utils.h" +#include "common.h" #include "dictionary/abstract.h" -typedef void * dictionary_group_t; - typedef enum { DICTIONARY_ERROR_VOID, @@ -33,7 +31,7 @@ typedef enum DICTIONARY_ERROR_INVALID_INDEX, } dictionary_error; -dictionary_group_t dictionary_group_open(void); +dictionary_group_t dictionary_group_open(dictionary_set_t t_dictionary_set); void dictionary_group_close(dictionary_group_t t_dictionary); @@ -54,4 +52,6 @@ dictionary_error dictionary_errno(void); void dictionary_perror(const char * spec); +dictionary_set_t dictionary_group_get_dictionary_set(dictionary_group_t t_dictionary); + #endif /* __DICTIONARY_GROUP_H_ */ diff --git a/src/dictionary_set.c b/src/dictionary_set.c index 57985ed..6866bb6 100644 --- a/src/dictionary_set.c +++ b/src/dictionary_set.c @@ -17,22 +17,25 @@ */ #include "dictionary_set.h" +#include "dictionary_group.h" #define DICTIONARY_GROUP_MAX_COUNT 128 struct _dictionary_set { + config_t config; size_t count; dictionary_group_t groups[DICTIONARY_GROUP_MAX_COUNT]; } ; typedef struct _dictionary_set dictionary_set_desc; -dictionary_set_t dictionary_set_open(void) +dictionary_set_t dictionary_set_open(config_t config) { dictionary_set_desc * dictionary_set = (dictionary_set_desc *) malloc(sizeof(dictionary_set_desc)); dictionary_set->count = 0; + dictionary_set->config = config; return dictionary_set; } @@ -57,7 +60,7 @@ dictionary_group_t dictionary_set_new_group(dictionary_set_t t_dictionary) return (dictionary_group_t) -1; } - dictionary_group_t group = dictionary_group_open(); + dictionary_group_t group = dictionary_group_open(t_dictionary); dictionary_set->groups[dictionary_set->count ++] = group; return group; @@ -67,7 +70,7 @@ dictionary_group_t dictionary_set_get_group(dictionary_set_t t_dictionary, size_ { dictionary_set_desc * dictionary_set = (dictionary_set_desc *) t_dictionary; - if (index < 0 || index >= dictionary_set->count) + if (index >= dictionary_set->count) { return (dictionary_group_t) -1; } @@ -80,3 +83,9 @@ size_t dictionary_set_count_group(dictionary_set_t t_dictionary) dictionary_set_desc * dictionary_set = (dictionary_set_desc *) t_dictionary; return dictionary_set->count; } + +config_t dictionary_set_get_config(dictionary_set_t t_dictionary) +{ + dictionary_set_desc * dictionary_set = (dictionary_set_desc *) t_dictionary; + return dictionary_set->config; +} diff --git a/src/dictionary_set.h b/src/dictionary_set.h index 39be7b6..0c67016 100644 --- a/src/dictionary_set.h +++ b/src/dictionary_set.h @@ -19,12 +19,9 @@ #ifndef __DICTIONARY_SET_H_ #define __DICTIONARY_SET_H_ -#include "utils.h" -#include "dictionary_group.h" +#include "common.h" -typedef void * dictionary_set_t; - -dictionary_set_t dictionary_set_open(void); +dictionary_set_t dictionary_set_open(config_t config); void dictionary_set_close(dictionary_set_t t_dictionary); @@ -34,4 +31,6 @@ dictionary_group_t dictionary_set_get_group(dictionary_set_t t_dictionary, size_ size_t dictionary_set_count_group(dictionary_set_t t_dictionary); +config_t dictionary_set_get_config(dictionary_set_t t_dictionary); + #endif /* __DICTIONARY_SET_H_ */ diff --git a/src/encoding.c b/src/encoding.c index 99e84f8..ff7cb89 100644 --- a/src/encoding.c +++ b/src/encoding.c @@ -103,7 +103,7 @@ ucs4_t * utf8_to_ucs4(const char * utf8, size_t length) byte[3] = utf8[i] & BITMASK(2); i += 4; } - else if (GET_BIT(utf8[i], 2) == 0) + else if (GET_BIT(utf8[i], 1) == 0) { /* U-04000000 - U-7FFFFFFF */ /* 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx */ diff --git a/src/encoding.h b/src/encoding.h index d54a526..34766aa 100644 --- a/src/encoding.h +++ b/src/encoding.h @@ -19,7 +19,7 @@ #ifndef __OPENCC_ENCODING_H_ #define __OPENCC_ENCODING_H_ -#include "utils.h" +#include "common.h" ucs4_t * utf8_to_ucs4(const char * utf8, size_t length); diff --git a/src/opencc.c b/src/opencc.c index 90cb7aa..07fe67a 100644 --- a/src/opencc.c +++ b/src/opencc.c @@ -16,12 +16,13 @@ * limitations under the License. */ +#include "common.h" #include "opencc.h" #include "config_reader.h" #include "converter.h" #include "dictionary_set.h" +#include "dictionary_group.h" #include "encoding.h" -#include "utils.h" typedef struct { @@ -70,7 +71,7 @@ char * opencc_convert_utf8(opencc_t t_opencc, const char * inbuf, size_t length) if (winbuf == (ucs4_t *) -1) { /* 輸入數據轉換失敗 */ - errnum = OPENCC_ERROR_ENCODIND; + errnum = OPENCC_ERROR_ENCODING; return (char *) -1; } @@ -112,7 +113,7 @@ char * opencc_convert_utf8(opencc_t t_opencc, const char * inbuf, size_t length) free(outbuf); free(winbuf); free(woutbuf); - errnum = OPENCC_ERROR_ENCODIND; + errnum = OPENCC_ERROR_ENCODING; return (char *) -1; } @@ -159,9 +160,11 @@ opencc_t opencc_open(const char * config_file) converter_set_conversion_mode(opencc->converter, OPENCC_CONVERSION_FAST); /* 加載默認辭典 */ - int retval; if (config_file == NULL) - retval = 0; + { + /*TODO load default*/ + assert(0); + } else { config_t config = config_open(config_file); @@ -207,7 +210,7 @@ int opencc_dict_load(opencc_t t_opencc, const char * dict_filename, dictionary_group_t dictionary_group; if (opencc->dictionary_set == NULL) { - opencc->dictionary_set = dictionary_set_open(); + opencc->dictionary_set = dictionary_set_open(NULL); dictionary_group = dictionary_set_new_group(opencc->dictionary_set); } else @@ -267,7 +270,7 @@ void opencc_perror(const char * spec) case OPENCC_ERROR_CONVERTER: converter_perror(_("Converter error")); break; - case OPENCC_ERROR_ENCODIND: + case OPENCC_ERROR_ENCODING: perr(_("Encoding error")); break; default: diff --git a/src/opencc.h b/src/opencc.h index 374b00d..e431559 100644 --- a/src/opencc.h +++ b/src/opencc.h @@ -36,7 +36,8 @@ extern "C" { /** * opencc_open: * @config_file: Location of configuration file. - * @returns: A description pointer of the newly allocated instance of opencc. + * @returns: A description pointer of the newly allocated instance of opencc. On + * any error the return value will be (opencc_t) -1 * * Make an instance of opencc. * @@ -77,7 +78,8 @@ size_t opencc_convert(opencc_t od, ucs4_t ** inbuf, size_t * inbufleft, * opencc_convert_utf8: * @od: The opencc description pointer. * @inbuf: The UTF-8 encoded string. - * @length: The maximum number of characters in inbuf to convert. + * @length: The maximum length of inbuf to convert. If length is set to -1, + * the whole c-style string in inbuf will be converted. * * @returns: The newly allocated UTF-8 string that converted from inbuf. * diff --git a/src/opencc_types.h b/src/opencc_types.h index a26bebd..ad809fa 100644 --- a/src/opencc_types.h +++ b/src/opencc_types.h @@ -35,7 +35,8 @@ enum _opencc_error OPENCC_ERROR_VOID, OPENCC_ERROR_DICTLOAD, OPENCC_ERROR_CONFIG, - OPENCC_ERROR_ENCODIND, + OPENCC_ERROR_ENCODING, + OPENCC_ERROR_ENCODIND = OPENCC_ERROR_ENCODING, OPENCC_ERROR_CONVERTER, }; typedef enum _opencc_error opencc_error; @@ -49,9 +50,9 @@ typedef enum _opencc_dictionary_type opencc_dictionary_type; enum _opencc_conversion_mode { - OPENCC_CONVERSION_FAST, - OPENCC_CONVERSION_SEGMENT_ONLY, - OPENCC_CONVERSION_LIST_CANDIDATES, + OPENCC_CONVERSION_FAST = 0, + OPENCC_CONVERSION_SEGMENT_ONLY = 1, + OPENCC_CONVERSION_LIST_CANDIDATES = 2, }; typedef enum _opencc_conversion_mode opencc_conversion_mode; diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt index 2158b05..fa5ba1a 100644 --- a/src/tools/CMakeLists.txt +++ b/src/tools/CMakeLists.txt @@ -14,6 +14,10 @@ set( opencc_dict.c ../dictionary_group.c ../dictionary_group.h + ../dictionary_set.c + ../dictionary_set.h + ../config_reader.c + ../config_reader.h ../encoding.c ../encoding.h ../utils.c diff --git a/src/tools/opencc.c b/src/tools/opencc.c index 9514dc6..7810f5b 100644 --- a/src/tools/opencc.c +++ b/src/tools/opencc.c @@ -24,7 +24,7 @@ #include #include -#define BUFFER_SIZE 32768 +#define BUFFER_SIZE 65536 void convert(const char * input_file, const char * output_file, const char * config_file) { @@ -46,6 +46,7 @@ void convert(const char * input_file, const char * output_file, const char * con fprintf(stderr, _("Can not read file: %s\n"), input_file); exit(1); } + skip_utf8_bom(fp); } if (output_file) @@ -61,33 +62,48 @@ void convert(const char * input_file, const char * output_file, const char * con size_t size = BUFFER_SIZE; char * buffer_in = NULL, * buffer_out = NULL; buffer_in = (char *) malloc(size * sizeof(char)); - - while (fgets(buffer_in, size, fp) != NULL) - { - size_t freesize = size; - - char * buffer_in_p = buffer_in; - size_t line_length = strlen(buffer_in_p); - while (line_length + 1 == freesize && buffer_in_p[line_length - 2] != '\n') - { - //如果一行沒讀完,則最後一個字符不是換行,且讀滿緩衝區 - buffer_in_p += size - 1; - freesize = size + 1; - size += size; - size_t offset = buffer_in_p - buffer_in; - buffer_in = (char *) realloc(buffer_in, size * sizeof(char)); - buffer_in_p = buffer_in + offset; - - if (fgets(buffer_in_p, freesize, fp) == NULL) - break; - - line_length = strlen(buffer_in_p); - } - + + char* lookahead = (char*) malloc(size * sizeof(char)); + size_t lookahead_size = 0; + + while (!feof(fp)) + { + size_t read; + + if (lookahead_size > 0) { + memcpy(buffer_in, lookahead, lookahead_size); + read = fread(buffer_in + lookahead_size, 1, size - lookahead_size, fp) + lookahead_size; + lookahead_size = 0; + } + else + read = fread(buffer_in, 1, size, fp); + + // If we haven't finished reading after filling the entire buffer, + // then it could be that we broke within an UTF-8 character, in + // that case we must backtrack and find the boundary + if (read == size) { + // Find the boundary of last UTF-8 character + int i; + for (i = read - 1; i >= 0; i--) + { + char c = buffer_in[i]; + if (!(c & 0x80) || ((c & 0xC0) == 0xC0)) + break; + } + + assert(i >= 0); + memcpy(lookahead, buffer_in + i, read - i); + lookahead_size = read - i; + buffer_in[i] = '\0'; + } + else + buffer_in[read] = '\0'; + buffer_out = opencc_convert_utf8(od, buffer_in, (size_t) -1); if (buffer_out != (char *) -1) { fprintf(fpo, "%s", buffer_out); + free(buffer_out); } else { @@ -95,11 +111,24 @@ void convert(const char * input_file, const char * output_file, const char * con break; } } + + if (lookahead_size > 0) { + assert(lookahead_size < size); + + lookahead[lookahead_size] = '\0'; + buffer_out = opencc_convert_utf8(od, lookahead, (size_t) -1); + if (buffer_out != (char*) -1) { + fprintf(fpo, "%s", buffer_out); + free(buffer_out); + } + else + opencc_perror(_("OpenCC error")); + } opencc_close(od); + free(lookahead); free(buffer_in); - free(buffer_out); fclose(fp); fclose(fpo); @@ -112,7 +141,7 @@ void show_version() printf(_("Version %s\n"), VERSION); printf(_("\n")); printf(_("Author: %s\n"), "BYVoid "); - printf(_("Bug Report: %s\n"), "http://code.google.com/p/open-chinese-convert/issues/entry"); + printf(_("Bug Report: %s\n"), "http://code.google.com/p/opencc/issues/entry"); printf(_("\n")); } @@ -154,7 +183,7 @@ int main(int argc, char ** argv) static int oc; static char *input_file, *output_file, *config_file; - while((oc = getopt_long(argc, argv, "vh:i:o:c:", longopts, NULL)) != -1) + while((oc = getopt_long(argc, argv, "vh?i:o:c:", longopts, NULL)) != -1) { switch (oc) { @@ -162,11 +191,9 @@ int main(int argc, char ** argv) show_version(); return 0; case 'h': + case '?': show_usage(); return 0; - case '?': - printf(_("Please use %s --help.\n"), argv[0]); - return 1; case 'i': input_file = mstrcpy(optarg); break; diff --git a/src/tools/opencc_dict.c b/src/tools/opencc_dict.c index 9c9514e..5447c78 100644 --- a/src/tools/opencc_dict.c +++ b/src/tools/opencc_dict.c @@ -124,7 +124,7 @@ void get_words_with_prefix(ucs4_t * word, int p) buff[p] = 0; words_set_count = 0; - for (i = binary_search(buff); i < lexicon_count && is_prefix(buff,lexicon[i].key); i ++) + for (i = binary_search(buff); (uint32_t)i < lexicon_count && is_prefix(buff,lexicon[i].key); i ++) { if (ucs4cmp(buff,lexicon[i].key) == 0) continue; @@ -167,10 +167,10 @@ void insert_first_char(int id) dat[key].word = (id); } -void insert_words(int delta, int parent,int word_len) +void insert_words(int delta, int parent, size_t word_len) { int i; - for (i = 0; i < words_set_count; i ++) + for (i = 0; (uint32_t)i < words_set_count; i ++) { int j = words_set[i]; int k = encode_char(lexicon[j].key[word_len]) + delta; @@ -188,10 +188,10 @@ void insert(int id) Entry * word = &lexicon[id]; for (;;) { - int p,i; + int p, i; match_word(dat, word->key, &p, &i, 0); - if (p == word->length) + if ((size_t)p == word->length) return; get_words_with_prefix(word->key, p); @@ -218,7 +218,7 @@ void insert(int id) void make(void) { - int i; + size_t i; for (i = 1; i < DATRIE_SIZE; i ++) { dat[i].parent = dat[i].base = DATRIE_UNUSED; @@ -239,7 +239,7 @@ int cmp(const void *a, const void *b) void init(const char * filename) { - dictionary_group_t dictionary_group = dictionary_group_open(); + dictionary_group_t dictionary_group = dictionary_group_open(NULL); if (dictionary_group_load(dictionary_group, filename, OPENCC_DICTIONARY_TYPE_TEXT) == -1) { diff --git a/src/utils.c b/src/utils.c index d8d446b..88935be 100644 --- a/src/utils.c +++ b/src/utils.c @@ -16,8 +16,23 @@ * limitations under the License. */ +#include #include "utils.h" +#ifdef __APPLE__ + #include "TargetConditionals.h" + #ifdef TARGET_OS_MAC + #include + #elif TARGET_OS_IPHONE + #elif TARGET_IPHONE_SIMULATOR + #else + #endif +#elif defined _WIN32 || defined _WIN64 + #include +#endif + +#define PATH_BUFFER_SIZE 4096 + void perr(const char * str) { fputs(str, stderr); @@ -42,3 +57,117 @@ char * mstrncpy(const char * str, size_t n) strbuf[n] = '\0'; return strbuf; } + +void skip_utf8_bom(FILE *fp) +{ + int bom[3]; + int n; + /* UTF-8 BOM is EF BB BF */ + if (fp == NULL) + return; + /* If we are not at beginning of file, return */ + if (ftell(fp) != 0) { + return; + } + /* Try to read first 3 bytes */ + for (n = 0; n <= 2 && (bom[n] = getc(fp)) != EOF; n++) { + ; + } + /* If we can only read <3 bytes, push them back */ + /* Or if first 3 bytes is not BOM, push them back */ + if (n < 3 || bom[0] != 0xEF || bom[1] != 0xBB || bom[2] != 0xBF) { + for (n-- ; n >= 0; n--) { + ungetc(bom[n], fp); + } + } + /* Otherwise, BOM is already skipped */ +} + +const char * executable_path(void) +{ + static char path_buffer[PATH_BUFFER_SIZE]; + static int calculated = FALSE; + if (!calculated) + { +#ifdef __linux + ssize_t res = readlink("/proc/self/exe", path_buffer, sizeof(path_buffer)); + assert(res != -1); +#elif __APPLE__ + uint32_t size = sizeof(path_buffer); + int res = _NSGetExecutablePath(path_buffer, &size); + assert(res == 0); +#elif _WIN32 || _WIN64 + // TODO windows + assert(false); +#else + /* Other unsupported os */ + assert(false); +#endif + char * last_sep = strrchr(path_buffer, '/'); + assert(last_sep != NULL); + *last_sep = '\0'; + calculated = TRUE; + } + return path_buffer; +} + +char * try_open_file(const char * path) +{ + /* Try to find file in current working directory */ + FILE * fp = fopen(path, "r"); + if (fp) + { + fclose(fp); + return mstrcpy(path); + } + /* If path is absolute, return NULL */ + if (is_absolute_path(path)) + { + return NULL; + } + /* Try to find file in executable directory*/ + const char * exe_dir = executable_path(); + char * filename = (char *) malloc(sizeof(char) * (strlen(path) + strlen(exe_dir) + 2)); + sprintf(filename, "%s/%s", exe_dir, path); + fp = fopen(filename, "r"); + if (fp) + { + fclose(fp); + return filename; + } + free(filename); + /* Try to use PKGDATADIR */ + filename = (char *) malloc(sizeof(char) * (strlen(path) + strlen(PKGDATADIR) + 2)); + sprintf(filename, "%s/%s", PKGDATADIR, path); + fp = fopen(filename, "r"); + if (fp) + { + fclose(fp); + return filename; + } + free(filename); + return NULL; +} + +char * get_file_path(const char * filename) +{ + const char * last_sep = strrchr(filename, '/'); + if (last_sep == NULL) { + last_sep = filename; + } + char * path = mstrncpy(filename, last_sep - filename); + return path; +} + +int is_absolute_path(const char * path) +{ + if (path[0] == '/') + { + return TRUE; + } + if (path[1] == ':') + { + return TRUE; + } + return FALSE; +} diff --git a/src/utils.h b/src/utils.h index 2dfd4b5..cfa1191 100644 --- a/src/utils.h +++ b/src/utils.h @@ -19,32 +19,7 @@ #ifndef __OPENCC_UTILS_H_ #define __OPENCC_UTILS_H_ -#include -#include -#include -#include - -#include "opencc_types.h" - -#define FALSE (0) -#define TRUE (!(0)) -#define INFINITY_INT ((~0U)>>1) - -#ifndef BIG_ENDIAN -# define BIG_ENDIAN (0) -#endif - -#ifndef LITTLE_ENDIAN -# define LITTLE_ENDIAN (1) -#endif - -#ifdef ENABLE_GETTEXT -# include -# include -# define _(STRING) dgettext(PACKAGE_NAME, STRING) -#else -# define _(STRING) STRING -#endif +#include "common.h" #define debug_should_not_be_here() \ do { \ @@ -60,4 +35,14 @@ char * mstrcpy(const char * str); char * mstrncpy(const char * str, size_t n); +void skip_utf8_bom(FILE *fp); + +const char * executable_path(void); + +char * try_open_file(const char * path); + +char * get_file_path(const char * filename); + +int is_absolute_path(const char * path); + #endif /* __OPENCC_UTILS_H_ */ -- 2.30.2